From 8b8e00633cb7f4c69b0312167463df1b1c33d833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 15:38:35 +0300 Subject: [PATCH 1/8] Solution --- db/models.py | 12 ++++++++++++ main.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/db/models.py b/db/models.py index 137941ff..51233bf7 100644 --- a/db/models.py +++ b/db/models.py @@ -1 +1,13 @@ from django.db import models + + +class Genre(models.Model): + name = models.CharField(max_length=63) + + +class Actor(models.Model): + first_name = models.CharField(max_length=63) + last_name = models.CharField(max_length=63) + + + diff --git a/main.py b/main.py index 545f938a..dedbe3d2 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,37 @@ import init_django_orm # noqa: F401 from django.db.models import QuerySet +from db.models import Genre, Actor def main() -> QuerySet: - pass + # create + list_of_genre = ["Western", "Action", "Dramma"] + list_of_actors = [["George", "Klooney"], + ["Kianu", "Reaves"], + ["Scarlett", "Keegan"], + ["Will", "Smith"], + ["Jaden", "Smith"], + ["Scarlett", "Johansson"]] + for genre in list_of_genre: + Genre.objects.create(name=genre) + for actor in list_of_actors: + Actor.objects.create(first_name=actor[0], last_name=actor[1]) + # update + Genre.objects.filter(name="Dramma").update(name="Drama") + Actor.objects.filter(last_name="Klooney").update(last_name="Clooney") + Actor.objects.filter(first_name="Kianu").update(first_name="Keanu") + Actor.objects.filter(last_name="Reaves").update(last_name="Reeves") + # delete + Genre.objects.filter(name="Action").delete() + Actor.objects.filter(first_name="Scarlett").delete() + # return + list_of_smith = [] + for smith in Actor.objects.all(): + if smith.last_name == "Smith": + list_of_smith.append(smith) + return QuerySet.order_by(list_of_smith[1], list_of_smith[0]) + + +if __name__ == "__main__": + main() From 1c9f1834cfc226d7a81748056d5b803661d4a78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 15:39:55 +0300 Subject: [PATCH 2/8] Solution --- db/models.py | 3 --- main.py | 4 ---- 2 files changed, 7 deletions(-) diff --git a/db/models.py b/db/models.py index 51233bf7..78940c17 100644 --- a/db/models.py +++ b/db/models.py @@ -8,6 +8,3 @@ class Genre(models.Model): class Actor(models.Model): first_name = models.CharField(max_length=63) last_name = models.CharField(max_length=63) - - - diff --git a/main.py b/main.py index dedbe3d2..8ef908b2 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,3 @@ def main() -> QuerySet: if smith.last_name == "Smith": list_of_smith.append(smith) return QuerySet.order_by(list_of_smith[1], list_of_smith[0]) - - -if __name__ == "__main__": - main() From 1a8bb5cca374f641c2e2434041e8d30b77693789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 17:17:03 +0300 Subject: [PATCH 3/8] Solution --- main.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 8ef908b2..6f787a8a 100644 --- a/main.py +++ b/main.py @@ -26,8 +26,5 @@ def main() -> QuerySet: Genre.objects.filter(name="Action").delete() Actor.objects.filter(first_name="Scarlett").delete() # return - list_of_smith = [] - for smith in Actor.objects.all(): - if smith.last_name == "Smith": - list_of_smith.append(smith) - return QuerySet.order_by(list_of_smith[1], list_of_smith[0]) + return Actor.objects.filter(last_name="Smith").order_by("first_name") + From 8544d929ee3779416a6b4d2130b1fb1dbca5fe7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 17:18:40 +0300 Subject: [PATCH 4/8] Solution --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 6f787a8a..d14681bd 100644 --- a/main.py +++ b/main.py @@ -27,4 +27,3 @@ def main() -> QuerySet: Actor.objects.filter(first_name="Scarlett").delete() # return return Actor.objects.filter(last_name="Smith").order_by("first_name") - From bd1b786c7f9690827056dc52209e009537a284c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 17:49:10 +0300 Subject: [PATCH 5/8] Solution --- db/migrations/0001_initial.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 db/migrations/0001_initial.py diff --git a/db/migrations/0001_initial.py b/db/migrations/0001_initial.py new file mode 100644 index 00000000..f9d83cb3 --- /dev/null +++ b/db/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.6 on 2023-10-17 14:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Actor', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=63)), + ('last_name', models.CharField(max_length=63)), + ], + ), + migrations.CreateModel( + name='Genre', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=63)), + ], + ), + ] From 0ffba604752b22693d60c67105b79d39ff66b3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 18:51:04 +0300 Subject: [PATCH 6/8] Solution --- db/migrations/0001_initial.py | 14 +++++++------- main.py | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/db/migrations/0001_initial.py b/db/migrations/0001_initial.py index f9d83cb3..a5206ecc 100644 --- a/db/migrations/0001_initial.py +++ b/db/migrations/0001_initial.py @@ -12,18 +12,18 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Actor', + name="Actor", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('first_name', models.CharField(max_length=63)), - ('last_name', models.CharField(max_length=63)), + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ("first_name", models.CharField(max_length=63)), + ("last_name", models.CharField(max_length=63)), ], ), migrations.CreateModel( - name='Genre', + name="Genre", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=63)), + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ("name", models.CharField(max_length=63)), ], ), ] diff --git a/main.py b/main.py index d14681bd..3d8c76a8 100644 --- a/main.py +++ b/main.py @@ -6,16 +6,16 @@ def main() -> QuerySet: # create - list_of_genre = ["Western", "Action", "Dramma"] - list_of_actors = [["George", "Klooney"], + genres = ["Western", "Action", "Dramma"] + actors = [["George", "Klooney"], ["Kianu", "Reaves"], ["Scarlett", "Keegan"], ["Will", "Smith"], ["Jaden", "Smith"], ["Scarlett", "Johansson"]] - for genre in list_of_genre: + for genre in genres: Genre.objects.create(name=genre) - for actor in list_of_actors: + for actor in actors: Actor.objects.create(first_name=actor[0], last_name=actor[1]) # update Genre.objects.filter(name="Dramma").update(name="Drama") From 74342c77d7253ee7c3b801e3a809d17bcc3056d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 20:58:20 +0300 Subject: [PATCH 7/8] Solution --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 3d8c76a8..1111721f 100644 --- a/main.py +++ b/main.py @@ -8,11 +8,11 @@ def main() -> QuerySet: # create genres = ["Western", "Action", "Dramma"] actors = [["George", "Klooney"], - ["Kianu", "Reaves"], - ["Scarlett", "Keegan"], - ["Will", "Smith"], - ["Jaden", "Smith"], - ["Scarlett", "Johansson"]] + ["Kianu", "Reaves"], + ["Scarlett", "Keegan"], + ["Will", "Smith"], + ["Jaden", "Smith"], + ["Scarlett", "Johansson"]] for genre in genres: Genre.objects.create(name=genre) for actor in actors: From 61cf1c207e90631038827243c7a6fd5cb89c3068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=9F=D0=BE=D0=BD=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 17 Oct 2023 21:42:56 +0300 Subject: [PATCH 8/8] Solution --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 1111721f..76da1548 100644 --- a/main.py +++ b/main.py @@ -15,8 +15,8 @@ def main() -> QuerySet: ["Scarlett", "Johansson"]] for genre in genres: Genre.objects.create(name=genre) - for actor in actors: - Actor.objects.create(first_name=actor[0], last_name=actor[1]) + for first_name, last_name in actors: + Actor.objects.create(first_name=first_name, last_name=last_name) # update Genre.objects.filter(name="Dramma").update(name="Drama") Actor.objects.filter(last_name="Klooney").update(last_name="Clooney")