Django’s ORM creates multiple aliases for the same Model instance. In certain situations this may result in problematic behavior, as multiple operations on the same instance are interleaved, however, field access happens on different aliases of the instance, ultimately resulting in loss of updates. Read more »
Articles with tag: Django
Ordering on a field in the ‘through’ Model of a recursive ManyToMany relation in Django
It is not possible to order a Model on a field of the Model acting as the intermediate ‘through‘ of a ManyToMany relation in Django, because queries will not return items in the correct order, and in addition will include duplicate items, even when using .distinct().
This problem is current as of Django 1.3 and has no generic solution as far as I know.
Duplicate items when ordering by Generic Relation in Django
When the optional ordering = … attribute of a model’s Meta class contains a GenericRelation from the Content Types framework in Django, there is no way to eliminate duplicate items being returned, even when using .distinct() (since .order_by(…) is applied by the ORM only after the SQL SELECT DISTINCT clause is built).
This problem is current as of Django 1.3 and has no generic solution as far as I know.