Skip to content

Commit

Permalink
Only require that showtimes be unique.
Browse files Browse the repository at this point in the history
For whatever reason, showtime__date uniqueness was not being enforced
correctly. I don't understand why.

If possible, it'd be neat to have the other two `Show.clean()`
restrictions be enforced as constraints.
  • Loading branch information
colons committed Jan 8, 2024
1 parent c42021f commit 60710e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name='show',
constraint=models.UniqueConstraint(
models.F('showtime__date'), name='unique_showtime_dates'
models.F('showtime'), name='unique_showtime'
),
),
]
5 changes: 1 addition & 4 deletions nkdsu/apps/vote/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ class Show(CleanOnSaveMixin, Serializable, models.Model):

class Meta:
constraints = [
models.UniqueConstraint(
'showtime__date',
name='unique_showtime_dates',
),
models.UniqueConstraint('showtime', name='unique_showtime'),
]
ordering = ['-showtime']

Expand Down
4 changes: 2 additions & 2 deletions nkdsu/apps/vote/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def test_showtime_date_constraint(self) -> None:

with self.assertRaises(ValidationError) as e:
Show.objects.create(
showtime='2038-01-01T16:00:00Z', end='2038-01-01T18:00:00Z'
showtime='2038-01-01T12:00:00Z', end='2038-01-01T12:00:00Z'
)
self.assertEqual(
str(e.exception),
str({'__all__': ['Constraint “unique_showtime_dates” is violated.']}),
str({'__all__': ['Constraint “unique_showtime” is violated.']}),
)

Show.objects.create(showtime='2038-01-02T12:00:00Z', end='2038-01-02T14:00:00Z')
Expand Down

0 comments on commit 60710e3

Please sign in to comment.