Q:

Save many to many fields in django view in a certein order

I have a ManyToMany model in django app:
class Colors(models.Model):
    color = models.CharField(max_length=30)

class Cars(models.Model):
    brand = models.CharField(max_length=30)

class Lote(models.Model):
    adress = models.CharField(max_length=100)
    cars = models.ManyToManyField(Cars)
    color = models.ManyToManyField(Cars)

Im trying to save a new Lote() with two pk lists:
colors_pk = [1,2,3]
cars_pk = [3,1,2]

My question is: if i save Lote() instance like this:
lote = Lote(adress='Some address')
lote.save()
lote.cars.add(cars_pk)
lote.color.add(colors_pk)

will the colors and cars be saved on m2m field in the same order as the list? because the order of the lists is important - colors_pk and cars_pk are related by index i.e. car 3 is linked to color 1.
So how should I do it?

A:

I would redesign your models as such: 
class Color(models.Model):
    color = models.CharField(max_length=30)

class Car(models.Model):
    brand = models.CharField(max_length=30)
    color = models.ManyToManyField(Color)

class Lot(models.Model):
    address = models.CharField(max_length=100)
    cars = models.ManyToManyField(Car)

This leaves Cars related to Lote, and Colors by extension, but ensures that Colors are properly linked to Cars. 

