Opened 19 years ago
Closed 18 years ago
#1683 closed defect (fixed)
[patch][magic removal] fixed model objects set-properties to be settable in constructor
Reported by: | iki (admin at mail cz) | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Metasystem | Version: | magic-removal |
Severity: | trivial | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, django.db.models.base.Model._init_ does not accept object set-properties as its keyword arguments. See example below for more info. Attached is a trivial patch.
Example.model:
from django.db import models class User(models.Model): first_name = models.CharField(maxlength=30, blank=False) last_name = models.CharField(maxlength=30, blank=False) def _get_name(self): return '%s %s' % (self.first_name, self.last_name) def _set_name(self, name): split = name.rfind(' ') self.last_name = name[split+1:] if (split < 0): split = 0 self.first_name = name[:split] name = property(_get_name, _set_name)
Example.code:
u = User(name='Petr Iljic Cajkovskij')
Result.beforePatch:
TypeError: 'name' is an invalid keyword argument for this function
Attachments (1)
Change History (3)
by , 19 years ago
Attachment: | base.py.diff added |
---|
comment:1 by , 19 years ago
Summary: | [patch] fixed model objects set-properties to be settable in constructor → [patch][magic removal] fixed model objects set-properties to be settable in constructor |
---|
comment:2 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
(In [3145]) Fixed #1683 -- Permit initialising models using settable properties as well as
field names.