python - Django Tutorial: Where does the other objects come from? -
i have been reading , following django tutorial https://docs.djangoproject.com/en/1.3/intro/tutorial01/ running django 1.3.1, , python 2.7.3 on xubuntu 12.04 lts virtual machine 512 mb ram if matters.
actually found exact question, reference seems out of date. have viable link reference? where 'article_set' come in django?
thank in advance.
django foreignkey lookups establish relations between related objects. these relations added dynamically accessors suffixed _set
def get_accessor_name(self): # method encapsulates logic decides name give # accessor descriptor retrieves related many-to-one or # many-to-many objects. uses lower-cased object_name + "_set", # can overridden "related_name" option. if self.field.rel.multiple: # if symmetrical m2m relation on self, there no reverse accessor. if getattr(self.field.rel, 'symmetrical', false) , self.model == self.parent_model: return none return self.field.rel.related_name or (self.opts.object_name.lower() + '_set') else: return self.field.rel.related_name or (self.opts.object_name.lower())
code in django sources (models/related.py
)
Comments
Post a Comment