hey, I want to create an image catalog so I have those classes:
class CatalogImage(models.Model):
title = models.CharField(max_length=120, verbose_name=_("title"))
description = models.TextField(verbose_name=_("description"))
image = models.ImageField(verbose_name=_("image"))
image_thumbnail = models.ImageField(verbose_name=_("image thumbnail"), null=True, blank=True)
class CatalogAlbum(MPTTModel):
title = models.CharField(max_length=120, verbose_name=_("title"))
slug = models.SlugField(max_length=120, verbose_name=_("slug"))
images = models.ManyToManyField(to=CatalogImage, related_name='images', blank=True, through='ThroughImage')
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
class ThroughImage(models.Model):
catalogImage = models.ForeignKey(CatalogImage, on_delete=models.CASCADE)
catalogAlbum = models.ForeignKey(CatalogAlbum, on_delete=models.CASCADE)
weight = models.IntegerField(verbose_name=_("weight"))
so it does works for me by setting the weight
in the ThrougImage
.
The problem is that every time I want to add a new photo to the middle of the album, I need to manually edit all the weights
for all the photos under it.
Does anyone have an idle about how to improve it?
Thank you!