From db92523a2a468bf29a0982df3cd15b0718139441 Mon Sep 17 00:00:00 2001 From: Ben Dichter Date: Thu, 26 Dec 2024 11:09:02 -0500 Subject: [PATCH] Ruff compliance for DandisetStar model and admin integration --- dandiapi/api/admin.py | 2 +- dandiapi/api/migrations/0014_dandisetstar.py | 30 +++++++++++++++++--- dandiapi/api/models/dandiset.py | 6 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/dandiapi/api/admin.py b/dandiapi/api/admin.py index bdf5bd6d5..a84f1fa53 100644 --- a/dandiapi/api/admin.py +++ b/dandiapi/api/admin.py @@ -21,10 +21,10 @@ AssetBlob, AuditRecord, Dandiset, + DandisetStar, Upload, UserMetadata, Version, - DandisetStar, ) from dandiapi.api.views.users import social_account_to_dict from dandiapi.zarr.tasks import ingest_dandiset_zarrs diff --git a/dandiapi/api/migrations/0014_dandisetstar.py b/dandiapi/api/migrations/0014_dandisetstar.py index a045bb19c..b9bf49a7c 100644 --- a/dandiapi/api/migrations/0014_dandisetstar.py +++ b/dandiapi/api/migrations/0014_dandisetstar.py @@ -1,4 +1,5 @@ # Generated by Django 4.2.17 on 2024-12-26 14:24 +from __future__ import annotations from django.conf import settings from django.db import migrations, models @@ -6,7 +7,6 @@ class Migration(migrations.Migration): - dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('api', '0013_remove_assetpath_consistent_slash_and_more'), @@ -16,10 +16,32 @@ class Migration(migrations.Migration): migrations.CreateModel( name='DandisetStar', fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ( + 'id', + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), ('created', models.DateTimeField(auto_now_add=True)), - ('dandiset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stars', to='api.dandiset')), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='starred_dandisets', to=settings.AUTH_USER_MODEL)), + ( + 'dandiset', + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='stars', + to='api.dandiset', + ), + ), + ( + 'user', + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='starred_dandisets', + to=settings.AUTH_USER_MODEL, + ), + ), ], options={ 'unique_together': {('user', 'dandiset')}, diff --git a/dandiapi/api/models/dandiset.py b/dandiapi/api/models/dandiset.py index ffc643482..30ea8afdd 100644 --- a/dandiapi/api/models/dandiset.py +++ b/dandiapi/api/models/dandiset.py @@ -1,11 +1,10 @@ from __future__ import annotations +from django.contrib.auth.models import User from django.db import models from django_extensions.db.models import TimeStampedModel from guardian.models import GroupObjectPermissionBase, UserObjectPermissionBase from guardian.shortcuts import assign_perm, get_objects_for_user, get_users_with_perms, remove_perm -from django.contrib.auth.models import User -from django.db.models import Count class DandisetManager(models.Manager): @@ -147,3 +146,6 @@ class DandisetStar(models.Model): class Meta: unique_together = ('user', 'dandiset') + + def __str__(self) -> str: + return f'Star {self.user.username} ★ {self.dandiset.identifier}'