From 15c779b08453442780a287b09f8d0389d9374e6c Mon Sep 17 00:00:00 2001 From: Kitaiskyi Oleksii Date: Wed, 4 Oct 2023 13:34:51 +0300 Subject: [PATCH 1/4] solution --- db/models.py | 9 +++++++++ main.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/db/models.py b/db/models.py index 137941ff..dc931c25 100644 --- a/db/models.py +++ b/db/models.py @@ -1 +1,10 @@ from django.db import models + + +class Genre(models.Model): + name = models.CharField(max_length=255) + + +class Actor(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) diff --git a/main.py b/main.py index 545f938a..97a259be 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,35 @@ from django.db.models import QuerySet +from db.models import Actor, Genre + def main() -> QuerySet: - pass + + genres = [ + "Western", "Action", "Dramma" + ] + + for genre in genres: + Genre.objects.create(name=genre) + + actors = [ + "George Klooney", "Kianu Reaves", + "Scarlett Keegan", "Will Smith", + "Jaden Smith", "Scarlett Johansson" + ] + + full_names = [name.split() for name in actors] + + for first_name, last_name in full_names: + Actor.objects.create(first_name=first_name, last_name=last_name) + + 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") + + Genre.objects.filter(name="Action").delete() + Actor.objects.filter(first_name="Scarlett").delete() + + return Actor.objects.filter(last_name="Smith").order_by("first_name") From 768836ce65c5a6c0d000b0a1db3606c2b21deaa0 Mon Sep 17 00:00:00 2001 From: Kitaiskyi Oleksii Date: Wed, 4 Oct 2023 13:49:40 +0300 Subject: [PATCH 2/4] res --- 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..404009f7 --- /dev/null +++ b/db/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.2 on 2023-10-04 05:41 + +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=255)), + ('last_name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Genre', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + ] From 2193291c08735f60fea0cb838f29df7d58d45ce4 Mon Sep 17 00:00:00 2001 From: Kitaiskyi Oleksii Date: Tue, 31 Oct 2023 09:36:32 +0200 Subject: [PATCH 3/4] tuples --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 97a259be..bb11a710 100644 --- a/main.py +++ b/main.py @@ -14,11 +14,11 @@ def main() -> QuerySet: for genre in genres: Genre.objects.create(name=genre) - actors = [ + actors = ( "George Klooney", "Kianu Reaves", "Scarlett Keegan", "Will Smith", "Jaden Smith", "Scarlett Johansson" - ] + ) full_names = [name.split() for name in actors] From 08319e4d5ddf89c2fbe4a85810e4df7c5729a431 Mon Sep 17 00:00:00 2001 From: Kitaiskyi Oleksii Date: Tue, 31 Oct 2023 09:37:49 +0200 Subject: [PATCH 4/4] missed tuple --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index bb11a710..e749178a 100644 --- a/main.py +++ b/main.py @@ -7,9 +7,9 @@ def main() -> QuerySet: - genres = [ + genres = ( "Western", "Action", "Dramma" - ] + ) for genre in genres: Genre.objects.create(name=genre)