def Contribute_to_class (self, CLS, name): self.set_attributes_from_name (name) = cls cls._ Meta.add_field (self) if self.choices: 'get_%s_display ' % self.name, Curry (Cls._get_field_display, FIELD=self)
The Contribute_to_class (self, CLS, name) defined above in the field class calls _meta.add_field (self)
defAdd_field (Self, field):#Insert the given field in the order in which it is created, using #the "Creation_counter" attribute of the field. #Move Many-to-many related fields from Self.fields into #Self.many_to_many. ifField.rel andisinstance (Field.rel, Manytomanyrel): Self.local_many_to_many.insert (Bisect (Self.local_many_to_many, field ), field)ifHasattr (Self,'_m2m_cache'): delSelf._m2m_cacheElse: Self.local_fields.insert (bisect (self.local_fields, field), field) self.setup_pk (field) ifHasattr (Self,'_field_cache'): delSelf._field_cachedelSelf._field_name_cacheifHasattr (Self,'_name_map'): delSelf._name_map
Add_field will add field to the Meta object.
Fields =Property (_fields)defGet_fields_with_model (self):"""Returns a sequence of (field, model) pairs for all fields. The "model" element is None of the for fields on the current model. Mostly of Use if constructing queries so, we know which model a field belongs to. """ Try: Self._field_cacheexceptAttributeerror:self._fill_fields_cache ()returnSelf._field_cachedef_fill_fields_cache (self): Cache= [] forParentinchself.parents: forfield, modelinchParent._meta.get_fields_with_model ():ifmodel:cache.append ((field, model))Else: Cache.append ((field, parent)) Cache.extend ([(F, None) forFinchSelf.local_fields]) Self._field_cache=tuple (cache) Self._field_name_cache= [x forX, _inchCache
Fields that call meta will return all field fields of model
Model instantiation to get all the field
The Django model is how to add fields to the meta