mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 21:21:57 +02:00
Blacked the code
This commit is contained in:
parent
b6fc0051fa
commit
62ca3bd736
279 changed files with 8861 additions and 9527 deletions
|
@ -5,7 +5,14 @@ from django.db import migrations, models
|
|||
|
||||
|
||||
def get_duplicates(model):
|
||||
return [i['mbid'] for i in model.objects.values('mbid').annotate(idcount=models.Count('mbid')).order_by('-idcount') if i['idcount'] > 1]
|
||||
return [
|
||||
i["mbid"]
|
||||
for i in model.objects.values("mbid")
|
||||
.annotate(idcount=models.Count("mbid"))
|
||||
.order_by("-idcount")
|
||||
if i["idcount"] > 1
|
||||
]
|
||||
|
||||
|
||||
def deduplicate(apps, schema_editor):
|
||||
Artist = apps.get_model("music", "Artist")
|
||||
|
@ -13,28 +20,25 @@ def deduplicate(apps, schema_editor):
|
|||
Track = apps.get_model("music", "Track")
|
||||
|
||||
for mbid in get_duplicates(Artist):
|
||||
ref = Artist.objects.filter(mbid=mbid).order_by('pk').first()
|
||||
ref = Artist.objects.filter(mbid=mbid).order_by("pk").first()
|
||||
duplicates = Artist.objects.filter(mbid=mbid).exclude(pk=ref.pk)
|
||||
Album.objects.filter(artist__in=duplicates).update(artist=ref)
|
||||
Track.objects.filter(artist__in=duplicates).update(artist=ref)
|
||||
duplicates.delete()
|
||||
|
||||
for mbid in get_duplicates(Album):
|
||||
ref = Album.objects.filter(mbid=mbid).order_by('pk').first()
|
||||
ref = Album.objects.filter(mbid=mbid).order_by("pk").first()
|
||||
duplicates = Album.objects.filter(mbid=mbid).exclude(pk=ref.pk)
|
||||
Track.objects.filter(album__in=duplicates).update(album=ref)
|
||||
duplicates.delete()
|
||||
|
||||
|
||||
def rewind(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0004_track_tags'),
|
||||
]
|
||||
dependencies = [("music", "0004_track_tags")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(deduplicate, rewind),
|
||||
]
|
||||
operations = [migrations.RunPython(deduplicate, rewind)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue