Skip to content

Commit

Permalink
annotation example
Browse files Browse the repository at this point in the history
  • Loading branch information
BrittleFoot committed Jun 5, 2024
1 parent dc3c5a1 commit 04653a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/books/migrations/0002_alter_book_author.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
4 changes: 3 additions & 1 deletion src/books/models.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 04653a4

Please sign in to comment.