From 899fd2b0879ee289db8af26f24c277fda587b042 Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 19:33:15 +0300 Subject: [PATCH 1/6] Solusion_1 --- db/models.py | 15 +++++++++++++++ main.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/db/models.py b/db/models.py index 137941ff..47797cf8 100644 --- a/db/models.py +++ b/db/models.py @@ -1 +1,16 @@ from django.db import models + + +class Genre(models.Model): + name = models.CharField(max_length=255) + + def __str__(self) -> str: + return f"{self.name}" + + +class Actor(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + + def __str__(self) -> str: + return f"{self.first_name} {self.last_name}" diff --git a/main.py b/main.py index 545f938a..092781cd 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,49 @@ import init_django_orm # noqa: F401 from django.db.models import QuerySet +from db.models import Actor, Genre def main() -> QuerySet: - pass + + Actor.objects.all().delete() + Genre.objects.all().delete() + Genre.objects.create(name="Western",) + Genre.objects.create(name="Action",) + Genre.objects.create(name="Dramma",) + + actors_first_name = ["George", "Kianu", "Scarlett", + "Will", "Jaden", "Scarlett"] + actors_last_name = ["Klooney", "Reaves", "Keegan", + "Smith", "Smith", "Johansson"] + + for number in range(len(actors_first_name)): + Actor.objects.create( + first_name=actors_first_name[number], + last_name=actors_last_name[number] + ) + + Genre.objects.filter( + name="Dramma", + ).update(name="Drama") + Actor.objects.filter( + last_name="Klooney" + ).update(last_name="Clooney") + Actor.objects.filter( + first_name="Kianu", + last_name="Reaves" + ).update(first_name="Keanu", last_name="Reeves") + + Genre.objects.filter(name="Action").delete() + Actor.objects.filter(first_name="Scarlett").delete() + + result = Actor.objects.filter( + last_name="Smith" + ).order_by("first_name") + return result + + +if __name__ == "__main__": + print(main()) + print(Genre.objects.all()) + print(Actor.objects.all()) From e0ffcfe4b27d902c517b84ab358223125ea1bb01 Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 20:27:37 +0300 Subject: [PATCH 2/6] Solsion_2 --- db/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/models.py b/db/models.py index 47797cf8..473aefc8 100644 --- a/db/models.py +++ b/db/models.py @@ -4,13 +4,13 @@ class Genre(models.Model): name = models.CharField(max_length=255) - def __str__(self) -> str: - return f"{self.name}" + # def __str__(self) -> str: + # return f"{self.name}" class Actor(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) - def __str__(self) -> str: - return f"{self.first_name} {self.last_name}" + # def __str__(self) -> str: + # return f"{self.first_name} {self.last_name}" From 0f96f80deda56e0325855ee1f842a0b91fbdd2ee Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 20:33:15 +0300 Subject: [PATCH 3/6] Solusion_3 --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 092781cd..6e3e649e 100644 --- a/main.py +++ b/main.py @@ -6,11 +6,11 @@ def main() -> QuerySet: - Actor.objects.all().delete() - Genre.objects.all().delete() - Genre.objects.create(name="Western",) - Genre.objects.create(name="Action",) - Genre.objects.create(name="Dramma",) + # Actor.objects.all().delete() + # Genre.objects.all().delete() + list_of_genre = ["Western", "Action", "Dramma"] + for genre in list_of_genre: + Genre.objects.create(name=genre,) actors_first_name = ["George", "Kianu", "Scarlett", "Will", "Jaden", "Scarlett"] From 507fd2e6b2927d963c30c32c4591a0461919263f Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 20:50:53 +0300 Subject: [PATCH 4/6] Solusion_3 --- db/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/models.py b/db/models.py index 473aefc8..47797cf8 100644 --- a/db/models.py +++ b/db/models.py @@ -4,13 +4,13 @@ class Genre(models.Model): name = models.CharField(max_length=255) - # def __str__(self) -> str: - # return f"{self.name}" + def __str__(self) -> str: + return f"{self.name}" class Actor(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) - # def __str__(self) -> str: - # return f"{self.first_name} {self.last_name}" + def __str__(self) -> str: + return f"{self.first_name} {self.last_name}" From 3a247e1a3c63cf1ba76dd5da0b084e52d242ac8a Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 20:53:38 +0300 Subject: [PATCH 5/6] Solusion --- 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..88ceb1b0 --- /dev/null +++ b/db/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.2 on 2023-10-23 16:23 + +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 e5d61e840a37c81f9e4b5b558ba8b440c5378156 Mon Sep 17 00:00:00 2001 From: Andrey Britov Date: Mon, 23 Oct 2023 21:06:54 +0300 Subject: [PATCH 6/6] Solusion_4 --- main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 6e3e649e..570cd1f2 100644 --- a/main.py +++ b/main.py @@ -12,15 +12,17 @@ def main() -> QuerySet: for genre in list_of_genre: Genre.objects.create(name=genre,) - actors_first_name = ["George", "Kianu", "Scarlett", - "Will", "Jaden", "Scarlett"] - actors_last_name = ["Klooney", "Reaves", "Keegan", - "Smith", "Smith", "Johansson"] - - for number in range(len(actors_first_name)): + actors_list = [("George", "Klooney"), + ("Kianu", "Reaves"), + ("Scarlett", "Keegan"), + ("Will", "Smith"), + ("Jaden", "Smith"), + ("Scarlett", "Johansson")] + + for first_name, last_name in actors_list: Actor.objects.create( - first_name=actors_first_name[number], - last_name=actors_last_name[number] + first_name=first_name, + last_name=last_name ) Genre.objects.filter(