Changes between Initial Version and Version 1 of Ticket #24804, comment 1


Ignore:
Timestamp:
May 15, 2015, 1:43:39 AM (9 years ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24804, comment 1

    initial v1  
    55When a model class is built its defined attributes such as fields are not necessarily ordered  the way they are defined; they are collected in an non-ordered mapping (`dict`) and thus the declared ordering is lost.
    66
    7 In your example you're assuming the `auto` field will be added after the `name` oen because the former is declared before. What's happening here is that `auto` is ordered before `name` in `attrs` and thus its `contribute_to_class` [https://github.com/django/django/blob/dce004ab72e26103a86e98994de7f2cef9321f9b/django/db/models/base.py#L156-L158 is called before].
     7In your example you're assuming the `auto` field will be added after the `name` one because the latter is declared before. What's happening here is that `auto` is ordered before `name` in `attrs` and thus its `contribute_to_class` [https://github.com/django/django/blob/dce004ab72e26103a86e98994de7f2cef9321f9b/django/db/models/base.py#L156-L158 is called before].
    88
    99You shouldn't assume that `dict` will be ordered in any way. For example, if you change the seed used to define a an order over unordered collection (`python -R`) you should be able to make the following example print either an empty tuple or a singleton containing the `name` field:
Back to Top