diff options
| author | Michal Petrucha <michal.petrucha@koniiiik.org> | 2016-04-19 22:34:08 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-05-03 09:06:26 -0400 |
| commit | 8a47ba679d2da0dee74671a53ba0cd918b433e34 (patch) | |
| tree | 651eb70e38c6ba7e688b0cfdd06715a4727a318e /django/db | |
| parent | 8a55982e7086ebd73458f52516732d9f25dd002b (diff) | |
Refs #16508 -- Made Model.__init__() aware of virtual fields.
It's no longer necessary for GenericForeignKey (and any other virtual fields)
to intercept the field's values using the pre_init signal.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/base.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 94031d76a9..2a6fa081a4 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -452,11 +452,14 @@ class Model(six.with_metaclass(ModelBase)): if kwargs: for prop in list(kwargs): try: - if isinstance(getattr(self.__class__, prop), property): + # Any remaining kwargs must correspond to properties or + # virtual fields. + if (isinstance(getattr(self.__class__, prop), property) or + self._meta.get_field(prop)): if kwargs[prop] is not DEFERRED: setattr(self, prop, kwargs[prop]) del kwargs[prop] - except AttributeError: + except (AttributeError, FieldDoesNotExist): pass if kwargs: raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0]) |
