diff options
| author | Tim Graham <timograham@gmail.com> | 2016-05-28 15:16:44 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-05-28 16:06:06 -0400 |
| commit | f529d0cb5855db2dfc8d0d39850dbb4793bc75c2 (patch) | |
| tree | 7be148495ef23a4825a522c2ca44908554d64c33 /django/db/models | |
| parent | fc644076cdb45b8c227ff3041540f281a2c0b007 (diff) | |
[1.10.x] Refs #24227 -- Fixed crash of ManyToManyField.value_from_object() on unsaved model instances.
This behavior was removed in 67d984413c9540074e4fe6aa033081a35cf192bc
but is needed to prevent a crash in formtools.
Backport of a4c20ae85b40c49e28d1b2227208e4f00d7820df from master
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/fields/related.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 2de9ec8abd..8add38d6b0 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1565,6 +1565,8 @@ class ManyToManyField(RelatedField): """ Return the value of this field in the given model instance. """ + if obj.pk is None: + return [] qs = getattr(obj, self.attname).all() if qs._result_cache is not None: return [item.pk for item in qs] |
