Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.8.7 & Django 4.1.1 へとアップデート #16

Merged
merged 4 commits into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -5,9 +5,12 @@
Scripts/
pyvenv.cfg
pip-selfcheck.json
env*/

#### backup files
*.dump
dump.json
ringo.db

### Python ###
# Byte-compiled / optimized / DLL files
Expand Down
2 changes: 1 addition & 1 deletion .python-version
@@ -1 +1 @@
3.8.6
3.10.7
34 changes: 17 additions & 17 deletions apps/api/tests/test_views.py
Expand Up @@ -18,16 +18,16 @@ def total_apples_expected():
TweetsFactory(name='シナノゴールド')

return '''[
{
"name": "シナノドルチェ",
"y": 2,
"color": "AntiqueWhite"
},
{
"name": "シナノゴールド",
"y": 5,
"color": "Gold"
},
{
"name": "シナノドルチェ",
"y": 2,
"color": "AntiqueWhite"
},
{
"name": "フジ",
"y": 3,
Expand Down Expand Up @@ -63,13 +63,13 @@ def total_apples_by_month_expected():

return '''[
{
"name": "フジ",
"name": "シナノゴールド",
"data": [
1,
1,
1,
0,
0,
1,
1,
0,
0,
0,
Expand All @@ -78,16 +78,16 @@ def total_apples_by_month_expected():
0,
0
],
"color": "Red"
"color": "Gold"
},
{
"name": "シナノゴールド",
"name": "シナノドルチェ",
"data": [
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
Expand All @@ -96,14 +96,14 @@ def total_apples_by_month_expected():
0,
0
],
"color": "Gold"
"color": "AntiqueWhite"
},
{
"name": "シナノドルチェ",
"name": "フジ",
"data": [
1,
1,
0,
1,
0,
0,
0,
Expand All @@ -114,7 +114,7 @@ def total_apples_by_month_expected():
0,
0
],
"color": "AntiqueWhite"
"color": "Red"
}
]'''

Expand Down
3 changes: 2 additions & 1 deletion apps/api/views.py
Expand Up @@ -66,7 +66,8 @@ def get(self, request, *args, **kwargs) -> RingoJsonResponse:
name = tweet['name']
quantities = [0] * 12

quantities[tweet['month'] - 1] = tweet['quantity']
# SQLiteの場合、日付は文字列での表現なため、int()で数値に変換する
quantities[int(tweet['month']) - 1] = tweet['quantity']

results.append({
'name': name,
Expand Down
23 changes: 23 additions & 0 deletions apps/tweets/migrations/0002_alter_lastsearch_id_alter_tweets_id.py
@@ -0,0 +1,23 @@
# Generated by Django 4.1.1 on 2022-09-13 11:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tweets', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='lastsearch',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='tweets',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
8 changes: 4 additions & 4 deletions apps/tweets/models.py
Expand Up @@ -23,10 +23,10 @@ def calculate_total_by_name_and_month(cls) -> QuerySet:

PostgreSQLの関数を使っているため、SQLiteなどでは動作しない
"""
return cls.objects.extra(select={'month': "date_part('month', tweeted_at)::int"}) \
.values('name', 'month') \
.annotate(quantity=models.Count('name')) \
.order_by('name', 'month')
return cls.objects.extra(select={'month': "strftime('%m', tweeted_at)"}) \
.values('name', 'month') \
.annotate(quantity=models.Count('name')) \
.order_by('name', 'month')


class LastSearch(models.Model):
Expand Down
12 changes: 7 additions & 5 deletions dj_ringo_tabetter/settings.py
Expand Up @@ -111,11 +111,10 @@
else:
# 開発環境の場合、engineも渡さないとエラーとなる
DATABASES = {
'default':
dj_database_url.config(
default='postgres://ringo:postgres@127.0.0.1:19876/ringo_tabetter_py',
engine=dj_database_url.SCHEMES['postgresql']
)
'default': {
'NAME': os.path.join(BASE_DIR, 'ringo.db'),
'ENGINE': 'django.db.backends.sqlite3',
}
}


Expand Down Expand Up @@ -174,3 +173,6 @@
STATIC_ROOT = 'staticfiles'

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Django3.2以降の対応:主キーのフィールドを明示的に設定
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
84 changes: 44 additions & 40 deletions requirements.txt
@@ -1,42 +1,46 @@
atomicwrites==1.3.0
attrs==19.1.0
certifi==2019.6.16
chardet==3.0.4
dj-database-url==0.5.0
Django==2.2.16
asgiref==3.5.2
atomicwrites==1.4.1
attrs==22.1.0
certifi==2022.6.15.1
chardet==5.0.0
charset-normalizer==2.1.1
dj-database-url==1.0.0
Django==4.1.1
django-dotenv==1.4.2
factory-boy==2.12.0
Faker==8.1.0
freezegun==0.3.12
gunicorn==19.9.0
idna==2.8
importlib-metadata==0.20
Jinja2==2.10.1
MarkupSafe==1.1.1
more-itertools==7.2.0
oauthlib==3.1.0
packaging==19.1
pip-review==1.0
pluggy==0.12.0
psycopg2==2.8.6
py==1.8.0
pyparsing==2.4.2
PySocks==1.7.0
pytest==5.1.2
pytest-django==3.5.1
pytest-freezegun==0.3.0.post1
python-dateutil==2.8.0
python-dotenv==0.10.3
pytz==2019.2
PyYAML==5.1.2
requests==2.22.0
requests-oauthlib==1.2.0
six==1.12.0
slacker==0.13.0
sqlparse==0.3.0
factory-boy==3.2.1
Faker==14.2.0
freezegun==1.2.2
gunicorn==20.1.0
idna==3.3
importlib-metadata==4.12.0
iniconfig==1.1.1
Jinja2==3.1.2
MarkupSafe==2.1.1
more-itertools==8.14.0
oauthlib==3.2.1
packaging==21.3
pip-review==1.2.0
pluggy==1.0.0
psycopg2==2.9.3
py==1.11.0
pyparsing==3.0.9
PySocks==1.7.1
pytest==7.1.3
pytest-django==4.5.2
pytest-freezegun==0.4.2
python-dateutil==2.8.2
python-dotenv==0.21.0
pytz==2022.2.1
PyYAML==6.0
requests==2.28.1
requests-oauthlib==1.3.1
six==1.16.0
slacker==0.14.0
sqlparse==0.4.2
text-unidecode==1.3
tweepy==3.8.0
urllib3==1.25.3
wcwidth==0.1.7
whitenoise==4.1.3
zipp==0.6.0
tomli==2.0.1
tweepy==4.10.1
urllib3==1.26.12
wcwidth==0.2.5
whitenoise==6.2.0
zipp==3.8.1