Saving multiple objects at once in admin panel

Hi guys, i need some help here. I'm trying to create multiple objects at once when saving in admin panel. But the problem is, only the last value in the loop is being saved. I tried setting the primary key to None.

Output should be: A-1 ,A-2 ,A-3 etc..

class Seat(models.Model):
    seat = models.CharField(default='Seat', max_length=5, unique=True, primary_key=False)
    theater = models.ForeignKey(Theater, on_delete=models.CASCADE)

    def clean(self):
        model = self.__class__
        if model.objects.count() >= self.theater.capacity:
            raise ValidationError(' - Maximum seats exceeded!')

    def save(self, *args, **kwargs):
        seats_name = []
        row_label = [chr(letter) for letter in range(65, 91)]
        row_track = 0
        row_range = 10

        col_range = self.theater.capacity // row_range
        col_track = 0

        for n in range(self.theater.capacity):
            row_track += 1

            if row_track > row_range:
                row_track = 1
                col_track += 1
            
            display = "{} | {}-{}".format(self.theater, row_label[col_track], row_track)
            seats_name.append(display)

        for seat in seats_name:
            self.seat = seat
        super(Seat, self).save(*args, **kwargs)

    def __str__(self):
        return self.seat

image

What does your admin class look like?

I just register the model classes on it.

Then how are you creating multiple Seat instances?

Or let me try asking it this way - What exactly are you trying to accomplish? Do you want to create some pattern of “Seat” objects in one Theater?

I don’t understand very well what the overall goal is. But do I understand correctly that you only want one set of form inputs, and then the code in your Model class is to generate a large number of Seat instances, that are to be saved to the database? I don’t know if that will work well with Django in general, but here:

for seat in seats_name:
    self.seat = seat
super(Seat, self).save(*args, **kwargs)

The only saving to the database, as far as I can tell, happens at super(Seat, self).save(*args, **kwargs). This is outside of the for loop, so it only happens once (using the last value of seats_name, as that is what self.seat is assigned at the end of the for loop). So you would have to move super(Seat, self).save(*args, **kwargs) inside the for loop to do what you want I think. But I have no idea if this might lead to other errors, since I don’t know if Django allows calling the Model.save() method repeatedly like this.