From fc6c6d95ab8186e03122343b48a5b4ddc603d722 Mon Sep 17 00:00:00 2001 From: Roman Zaliznyi Date: Thu, 19 Dec 2024 21:29:20 +0200 Subject: [PATCH] Solution --- db/migrations/0002_rename_name_genre_genre.py | 18 ++++++++++++++++++ db/models.py | 4 ++-- main.py | 10 +++++----- 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 db/migrations/0002_rename_name_genre_genre.py diff --git a/db/migrations/0002_rename_name_genre_genre.py b/db/migrations/0002_rename_name_genre_genre.py new file mode 100644 index 00000000..7b32033b --- /dev/null +++ b/db/migrations/0002_rename_name_genre_genre.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.2 on 2024-12-19 21:29 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='genre', + old_name='name', + new_name='genre', + ), + ] diff --git a/db/models.py b/db/models.py index 73ba623f..0e7b143e 100644 --- a/db/models.py +++ b/db/models.py @@ -2,10 +2,10 @@ class Genre(models.Model): - name = models.CharField(max_length=255) + genre = models.CharField(max_length=255) def __str__(self) -> str: - return self.name + return self.genre class Actor(models.Model): diff --git a/main.py b/main.py index 50732a0a..48ed05fa 100644 --- a/main.py +++ b/main.py @@ -5,9 +5,9 @@ def main() -> QuerySet: - Genre.objects.create(name="Western") - Genre.objects.create(name="Action") - Genre.objects.create(name="Dramma") + Genre.objects.create(genre="Western") + Genre.objects.create(genre="Action") + Genre.objects.create(genre="Dramma") Actor.objects.create(first_name="George", last_name="Klooney") Actor.objects.create(first_name="Kianu", last_name="Reaves") @@ -16,11 +16,11 @@ def main() -> QuerySet: Actor.objects.create(first_name="Jaden", last_name="Smith") Actor.objects.create(first_name="Scarlett", last_name="Johansson") - Genre.objects.filter(name="Dramma").update(genre="Drama") + Genre.objects.filter(genre="Dramma").update(genre="Drama") Actor.objects.filter(last_name="Klooney").update(last_name="Clooney") Actor.objects.filter(last_name="Keanu").update(last_name="Reeves") - Genre.objects.filter(name="Action").delete() + Genre.objects.filter(genre="Action").delete() Actor.objects.filter(first_name="Scarlett").delete() return Actor.objects.filter(last_name="Smith").order_by("first_name")