#28266 closed Bug (fixed)
Typo in docs/ref/models/instances.txt Model.from_db() code example
Reported by: | Lachlan Musicman | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I think it's because of a mislabelling. Note that a new cls is created and it's called new. After that it's referred to as instance.
@classmethod def from_db(cls, db, field_names, values): # Default implementation of from_db() (subject to change and could # be replaced with super()). if len(values) != len(cls._meta.concrete_fields): values = list(values) values.reverse() values = [ values.pop() if f.attname in field_names else DEFERRED for f in cls._meta.concrete_fields ] new = cls(*values) instance._state.adding = False instance._state.db = db # customization to store the original field values on the instance instance._loaded_values = dict(zip(field_names, values)) return instance
Should be
instance = cls(*values) instance._state.adding = False instance._state.db = db # customization to store the original field values on the instance instance._loaded_values = dict(zip(field_names, values)) return instance
Attachments (1)
Change History (5)
by , 8 years ago
Attachment: | 16df9cb6cc6188a53de32bbdcbb25fba54d83aa5.patch added |
---|
comment:1 by , 8 years ago
Summary: | from_db example in instance.txt doesn't work → Typo in docs/ref/models/instances.txt Model.from_db() code example |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
Type: | Uncategorized → Bug |
Note:
See TracTickets
for help on using tickets.
Patch file