diff --git a/gallery/models.py b/gallery/models.py index 24293d4..8e47cd1 100644 --- a/gallery/models.py +++ b/gallery/models.py @@ -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")