diff --git a/src/books/migrations/0002_alter_book_author.py b/src/books/migrations/0002_alter_book_author.py new file mode 100644 index 0000000..fdae9eb --- /dev/null +++ b/src/books/migrations/0002_alter_book_author.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.6 on 2024-06-05 11:17 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='author', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='books', to='books.author'), + ), + ] diff --git a/src/books/models.py b/src/books/models.py index bac8550..81d3b56 100644 --- a/src/books/models.py +++ b/src/books/models.py @@ -1,11 +1,13 @@ from app.models import TimestampedModel from django.db import models +from django.db.models.manager import Manager class Author(TimestampedModel): name = models.CharField(max_length=255) + books: "Manager[Book]" class Book(TimestampedModel): - author = models.ForeignKey(Author, on_delete=models.CASCADE) + author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name="books") name = models.CharField(max_length=255)