Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #1098

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
from django.db import models

class Genre(models.Model):
name = models.CharField(max_length=255)

def __str__(self):
return self.name


class Actor(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)

def __str__(self):
return f"{self.first_name} {self.last_name}"
37 changes: 36 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import init_django_orm # noqa: F401

from django.db.models import QuerySet
from db.models import Genre, Actor


def main() -> QuerySet:
pass
# Створення
western = Genre.objects.create(name="Western")
action = Genre.objects.create(name="Action")
drama = Genre.objects.create(name="Drama")

george = Actor.objects.create(first_name="George", last_name="Clooney")
keanu = Actor.objects.create(first_name="Keanu", last_name="Reeves")
scarlett = Actor.objects.create(first_name="Scarlett", last_name="Keegan")
will = Actor.objects.create(first_name="Will", last_name="Smith")
jaden = Actor.objects.create(first_name="Jaden", last_name="Smith")
scarlett_johansson = Actor.objects.create(
first_name="Scarlett", last_name="Johansson"
)

# Оновлення
drama.name = "Drama"
drama.save()

george.last_name = "Clooney"
george.save()

keanu.first_name = "Keanu"
keanu.last_name = "Reeves"
keanu.save()

# Видалення
action.delete()
Actor.objects.filter(first_name="Scarlett").delete()

# Повернення QuerySet акторів із прізвищем Smith, впорядкованих за іменем
actors_with_lastname_smith = Actor.objects.filter(
last_name="Smith"
).order_by("first_name")

return actors_with_lastname_smith
Loading