Update unique_slug

This commit is contained in:
Nyymix 2025-01-09 15:07:32 +02:00
parent 732834e598
commit ea92c2c788

View file

@ -65,14 +65,11 @@ class Photo(models.Model):
def _get_upload_path(instance, filename):
return os.path.join('albums', str(instance.album.slug), filename)
def _generate_unique_slug(self, datetime_taken=None):
datetime_taken = datetime_taken or datetime.now()
slug = datetime_taken.strftime('%y%m%d%H%M%S')
counter = 0
def _generate_unique_slug(self, datetime_taken=datetime.now()):
slug = int(datetime_taken.strftime('%y%m%d%H%M%S'))
while Photo.objects.filter(album=self.album, slug=slug).exists():
counter += 1
slug = (datetime_taken + timedelta(seconds=counter)).strftime('%y%m%d%H%M%S')
return slug
slug += 1
return str(slug)
album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name='photos', verbose_name="Album")
slug = models.CharField(max_length=15, editable=False, verbose_name="Photo Slug")