Django

Code

Ticket #1683 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch][magic removal] fixed model objects set-properties to be settable in constructor

Reported by: iki (admin at mail cz) Assigned to: adrian
Milestone: Component: Metasystem
Version: magic-removal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

base.py.diff (0.8 kB) - added by iki on 04/25/06 12:42:57.

Change History

04/25/06 12:42:57 changed by iki

  • attachment base.py.diff added.

05/08/06 06:45:26 changed by anonymous

  • summary changed from [patch] fixed model objects set-properties to be settable in constructor to [patch][magic removal] fixed model objects set-properties to be settable in constructor.

06/18/06 21:34:37 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [3145]) Fixed #1683 -- Permit initialising models using settable properties as well as field names.


Add/Change #1683 ([patch][magic removal] fixed model objects set-properties to be settable in constructor)




Change Properties
Action