From cb75655b0920b7411da01893bd5dded9ea8094d0 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 6 Dec 2024 15:30:44 +0200 Subject: [PATCH 1/2] 'Solution_v1.00' --- db/models.py | 9 +++++++++ main.py | 44 +++++++++++++++++++++++++++++++++++++++++++- settings.py | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) 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..ef23aa38 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 Genre, Actor def main() -> QuerySet: - pass + + for gen in ["Western", "Action", "Dramma"]: + Genre.objects.create(name=gen) + + actors = [ + ("George", "Klooney"), + ("Kianu", "Reaves"), + ("Scarlett", "Keegan"), + ("Will", "Smith"), + ("Jaden", "Smith"), + ("Scarlett", "Johansson") + ] + for actor_fname, actor_sname in actors: + Actor.objects.create(first_name=actor_fname, last_name=actor_sname) + + Genre.objects.filter( + name="Dramma" + ).update(name="Drama") + + Actor.objects.filter( + first_name="George", + 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() + + return Actor.objects.filter(last_name="Smith").order_by("first_name") + + +if __name__ == "__main__": + main() diff --git a/settings.py b/settings.py index 18760dec..802abe45 100644 --- a/settings.py +++ b/settings.py @@ -17,4 +17,4 @@ USE_TZ = False -INSTALLED_APPS = ("db",) +INSTALLED_APPS = ["db", ] From b879d74c16e21e872bd209d27c8782e30f04d3a3 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 6 Dec 2024 15:52:17 +0200 Subject: [PATCH 2/2] 'Solution_v1.01' --- main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.py b/main.py index ef23aa38..69447975 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,3 @@ def main() -> QuerySet: Actor.objects.filter(first_name="Scarlett").delete() return Actor.objects.filter(last_name="Smith").order_by("first_name") - - -if __name__ == "__main__": - main()