Suppose you have a many-to-many relation in a Django model, such as:
class GroceryList(models.Model):
items = models.ManyToManyField(GroceryItem, related
You can use the intermediate table using through and add the ordered field in that table.
class GroceryList(models.Model):
items = models.ManyToManyField(GroceryItem, related_name='in_lists',
through='Order')
class GroceryItem(models.Model):
name = models.CharField(unique=True)
class Order(models.Model):
number = models.PositiveIntegerField()
gl = models.ForeignKey(GroceryList)
gi = models.ForeignKey(GroceryItem)
So instead of doing grocerylist.items.add(groceryitem)
you can do
#for groceryitem1 as 1st item in grocerylist1
Order.objects.create(gl=grocerylist1, gi=groceryitem1, number=1)
#for groceryitem1 as 10th item in grocerylist2
Order.objects.create(gl=grocerylist2, gi=groceryitem1, number=10)