Code

Opened 8 years ago

Closed 8 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
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: UI/UX:

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)

base.py.diff (801 bytes) - added by iki 8 years ago.

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by iki

comment:1 Changed 8 years ago 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

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.