Skip to content

Commit

Permalink
👥 No duplicate authors (#198)
Browse files Browse the repository at this point in the history
# Authors
- Updates `AuthorsOrderable` to disallow duplicate authors
  - Using THIS ONE `unique_together` TRICK!!!
- Updates model to require `author` field of Orderable



Closes #194
  • Loading branch information
mrharpo authored Aug 29, 2024
1 parent 0efceae commit b700cfe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
22 changes: 22 additions & 0 deletions authors/migrations/0003_alter_authorsorderable_options_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.8 on 2024-08-28 18:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("authors", "0002_authorsorderable"),
("exhibits", "0013_alter_exhibitpage_body"),
]

operations = [
migrations.AlterModelOptions(
name="authorsorderable",
options={},
),
migrations.AlterUniqueTogether(
name="authorsorderable",
unique_together={("page", "author")},
),
]
32 changes: 32 additions & 0 deletions authors/migrations/0004_alter_authorsorderable_author_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.0.8 on 2024-08-29 18:48

import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("authors", "0003_alter_authorsorderable_options_and_more"),
("exhibits", "0013_alter_exhibitpage_body"),
]

operations = [
migrations.AlterField(
model_name="authorsorderable",
name="author",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="authors.author"
),
),
migrations.AlterField(
model_name="authorsorderable",
name="page",
field=modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="authors",
to="exhibits.exhibitpage",
),
),
]
8 changes: 5 additions & 3 deletions authors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@


class AuthorsOrderable(Orderable):
page = ParentalKey('exhibits.ExhibitPage', related_name='authors', null=True)

class Meta:
unique_together = ('page', 'author')

page = ParentalKey('exhibits.ExhibitPage', related_name='authors')
author = models.ForeignKey(
'authors.Author',
blank=True,
null=True,
on_delete=models.CASCADE,
)

Expand Down

0 comments on commit b700cfe

Please sign in to comment.