Skip to content

Commit

Permalink
Add starred_users m2m relation to Dandiset model
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Feb 5, 2025
1 parent afe79a3 commit 4a02dbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions dandiapi/api/migrations/0016_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:10
# Generated by Django 4.2.17 on 2025-02-05 18:25
from __future__ import annotations

from django.conf import settings
Expand All @@ -19,10 +19,7 @@ class Migration(migrations.Migration):
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
auto_created=True, primary_key=True, serialize=False, verbose_name='ID'
),
),
('created', models.DateTimeField(auto_now_add=True)),
Expand All @@ -38,12 +35,21 @@ class Migration(migrations.Migration):
'user',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='starred_dandisets',
related_name='dandiset_stars',
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.AddField(
model_name='dandiset',
name='starred_users',
field=models.ManyToManyField(
related_name='starred_dandisets',
through='api.DandisetStar',
to=settings.AUTH_USER_MODEL,
),
),
migrations.AddConstraint(
model_name='dandisetstar',
constraint=models.UniqueConstraint(
Expand Down
5 changes: 4 additions & 1 deletion dandiapi/api/models/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class EmbargoStatus(models.TextChoices):
choices=EmbargoStatus.choices,
default=EmbargoStatus.OPEN,
)
starred_users = models.ManyToManyField(
to=User, through='DandisetStar', related_name='starred_dandisets'
)

class Meta:
ordering = ['id']
Expand Down Expand Up @@ -78,7 +81,7 @@ class DandisetGroupObjectPermission(GroupObjectPermissionBase):


class DandisetStar(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='starred_dandisets')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='dandiset_stars')
dandiset = models.ForeignKey(Dandiset, on_delete=models.CASCADE, related_name='stars')
created = models.DateTimeField(auto_now_add=True)

Expand Down

0 comments on commit 4a02dbe

Please sign in to comment.