diff --git a/db/main.py b/db/main.py new file mode 100644 index 00000000..c4c15654 --- /dev/null +++ b/db/main.py @@ -0,0 +1,32 @@ +import init_django_orm # noqa: F401 + +from django.db.models import QuerySet +from db.models import Genre, Actor + + +def main() -> QuerySet: + + genres = ["Western", "Action", "Dramma"] + + actors = [ + ("George", "Klooney"), ("Kianu", "Reaves"), ("Scarlett", "Keegan"), + ("Will", "Smith"), ("Jaden", "Smith"), ("Scarlett", "Johansson") + ] + + for genre in genres: + Genre.objects.create(name=genre) + + for first_name, last_name in actors: + Actor.objects.create(first_name=first_name, last_name=last_name) + + 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").all().order_by("first_name") diff --git a/db/migrations/0001_initial.py b/db/migrations/0001_initial.py new file mode 100644 index 00000000..e21bc7d5 --- /dev/null +++ b/db/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# Generated by Django 5.1.3 on 2024-11-26 21:19 + +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)), + ], + ), + ] diff --git a/db/models.py b/db/models.py index 137941ff..51af6ba9 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 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}" \ No newline at end of file diff --git a/db/settings.py b/db/settings.py new file mode 100644 index 00000000..43201c79 --- /dev/null +++ b/db/settings.py @@ -0,0 +1,5 @@ +USE_TZ = False + +INSTALLED_APPS = ("db",) + +DEBUG = True \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 545f938a..00000000 --- a/main.py +++ /dev/null @@ -1,7 +0,0 @@ -import init_django_orm # noqa: F401 - -from django.db.models import QuerySet - - -def main() -> QuerySet: - pass diff --git a/settings.py b/settings.py deleted file mode 100644 index 18760dec..00000000 --- a/settings.py +++ /dev/null @@ -1,20 +0,0 @@ -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) - -# SECURITY WARNING: Modify this secret key if using in production! -SECRET_KEY = "6few3nci_q_o@l1dlbk81%wcxe!*6r29yu629&d97!hiqat9fa" - -DEFAULT_AUTO_FIELD = "django.db.models.AutoField" - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), - } -} - -USE_TZ = False - -INSTALLED_APPS = ("db",) diff --git a/tests/test_main.py b/tests/test_main.py index 166cb487..77224363 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,7 +2,7 @@ from db.models import Genre, Actor -from main import main +from db.main import main @pytest.mark.django_db