views:

172

answers:

1

Hi everyone,

We have been struggling with this for a few days and have done lots of searches on the web.

We are trying to figure out how entries are saved in Django forms for many to many fields.

For example we have a news model that has a many to many relationship with images. When we add images to a news article e.g. images with id 10,2,14 we can see the post values are the following when saving a news article form:

  • photos 10
  • photos 2
  • photos 14

When we look in the many to many intersection table the order has not been preserved. We can see no logic in the order the photos are inserted.

Hopefully that makes sense!

Many thanks for your answers in advance.

Arif

+2  A: 

Django doesn't guarantee to preserve the order of many-to-many relationships. If you need this, you should use a through table with an explicit 'order' field.

Daniel Roseman
Daniel,That is a huge help, many thanks for your response.Having looked at the docs you linked to that seems to solve the issue.Thanks.Arif
Arif