galery of images ordered by the admin

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!

How are you specifying the order of the photo when you put it in? Are you manually adding this through a view you’ve created, or using the Admin?

Either way, you could take a look at some of the third-party packages available such as django-admin-sortable to give you some ideas.

Thank you for your response!
I do use the admin page to edit my models.
I read abount django-admin-sortable and they have this example:

   | Parent Model 1 |               |
   |                | Child Model 1 |
   |                | Child Model 2 |
   | Parent Model 2 |               |
   |                | Child Model 3 |
   |                | Child Model 4 |
   |                | Child Model 5 |

but my code needs somthing more this this (every galery can have multiple images and 2 garerys can contain the same imge in diffrent order)

   | Parent Model 1 |               |
   |                | Child Model 1 | weight=1
   |                | Child Model 2 | weight=2
   | Parent Model 2 |               |
   |                | Child Model 2 | weight=1
   |                | Child Model 1 | weight=2
   |                | Child Model 3 | weight=3

I understand what you’re trying to do. I was thinking that the django-admin-sortable project might give you some ideas as to how you can implement what you need in the way you want to present it, I wasn’t thinking it was going to be a “plug-and-play” solution.