Skip to content

Commit

Permalink
Replace unique_together with UniqueConstraint
Browse files Browse the repository at this point in the history
unique_together is deprecated
  • Loading branch information
jjnesbitt committed Jan 3, 2025
1 parent 413e4ad commit 380a7eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions dandiapi/api/migrations/0014_dandisetstar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.17 on 2025-01-03 21:07
# Generated by Django 4.2.17 on 2025-01-03 21:10
from __future__ import annotations

from django.conf import settings
Expand Down Expand Up @@ -64,8 +64,11 @@ class Migration(migrations.Migration):
),
),
],
options={
'unique_together': {('user', 'dandiset')},
},
),
migrations.AddConstraint(
model_name='dandisetstar',
constraint=models.UniqueConstraint(
fields=('user', 'dandiset'), name='unique-user-dandiset-star'
),
),
]
4 changes: 3 additions & 1 deletion dandiapi/api/models/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class DandisetStar(models.Model):
created = models.DateTimeField(auto_now_add=True)

class Meta:
unique_together = ('user', 'dandiset')
constraints = [
models.UniqueConstraint(name='unique-user-dandiset-star', fields=['user', 'dandiset'])
]

def __str__(self) -> str:
return f'Star {self.user.username}{self.dandiset.identifier}'

0 comments on commit 380a7eb

Please sign in to comment.