If my models.py has a ManyToMany relationship between books and authors, and if for a particular SampleBook I execute: Sample_book.authors.add(author1) Sample_book.authors.add(author2) Sample_book.authors.add(author3)
are author1, author2, and author3 stored in books.authors.all in the order in which they were added?
i.e. is the ManyToMany add() function similar to an append? If I try to extract the values in a for loop, will they be returned in the order they were initially added?
Continued:
The answer received below stated that the db/ django did not bear responsibility for the order in which the objects were stored.
The problem is that I have a nested sort problem. e.g. I send over a list of books to the template, using order_by to sort it. But the template needs to display all the books, as well as all authors for each book, with the authors sorted as well.
Since there is a ManyToMany relationship between books and authors, the authors for each book are not necessarily stored in order (hence my original question). So the template displays books in the order passed, and I used regroup as a hack to sort the authors retrieved by association from each book.
Does anybody have a more elegant solution?