duplicate checking

This commit is contained in:
2024-02-19 21:18:53 +01:00
parent fcf31cb896
commit c48113a3cb
2 changed files with 17 additions and 0 deletions
+9
View File
@@ -2,6 +2,7 @@ from django.db import models
from random import choice
from .album import Album
from .artist import Artist
import re
class TrackManager(models.Manager):
def get_queryset(self):
@@ -10,6 +11,7 @@ class TrackManager(models.Manager):
class Track(models.Model):
def __str__(self):
s = f"'{self.name}'"
s += f" AKA '{self.name_sanitized}'"
if self.artists.count() > 0:
artists = list(map(lambda a:a.name, self.artists.all()))
s += " door "
@@ -20,6 +22,13 @@ class Track(models.Model):
if self.artists.count() > 0:
artists = list(map(lambda a:a.name, self.artists.all()))
return " & ".join(artists)
@property
def name_sanitized(self):
return re.match("[^\-\(]*\w", self.name)[0]
def is_duplicate_of(self):
return Track.objects.exclude(id=self.id).filter(name__startswith=self.name_sanitized).first()
id = models.CharField(primary_key=True, max_length=128)
name = models.CharField(max_length=255)