Update unique_slug
This commit is contained in:
parent
732834e598
commit
ea92c2c788
1 changed files with 4 additions and 7 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue