diff options
| author | Loic Bistuer <loic.bistuer@gmail.com> | 2015-02-14 01:55:36 +0700 |
|---|---|---|
| committer | Loic Bistuer <loic.bistuer@gmail.com> | 2015-02-14 02:28:24 +0700 |
| commit | 18c0aaa9123579375294fcc4a8ee7e3530176b88 (patch) | |
| tree | 00547fa5e4b2f3f975a11ddd8203fe971f5f95c2 /django | |
| parent | 5c995dcfc251b55284e1ef16545acd2acad6be04 (diff) | |
Fixed #24289 -- Reversed usage of Field.many_to_one and one_to_many.
Thanks Carl Meyer and Tim Graham for the reviews and to all involved
in the discussion.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/utils.py | 2 | ||||
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 8 | ||||
| -rw-r--r-- | django/db/models/deletion.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 8 | ||||
| -rw-r--r-- | django/db/models/options.py | 6 |
5 files changed, 13 insertions, 13 deletions
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 00d8b41129..5de0f09a48 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -296,7 +296,7 @@ def _get_non_gfk_field(opts, name): "not found" by get_field(). This could likely be cleaned up. """ field = opts.get_field(name) - if field.is_relation and field.one_to_many and not field.related_model: + if field.is_relation and field.many_to_one and not field.related_model: raise FieldDoesNotExist() return field diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index c11d6284c0..f47a5165ec 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -27,8 +27,8 @@ class GenericForeignKey(object): is_relation = True many_to_many = False - many_to_one = False - one_to_many = True + many_to_one = True + one_to_many = False one_to_one = False related_model = None @@ -269,8 +269,8 @@ class GenericRelation(ForeignObject): auto_created = False many_to_many = False - many_to_one = True - one_to_many = False + many_to_one = False + one_to_many = True one_to_one = False rel_class = GenericRel diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py index 431b15b0ef..02b8cf3c27 100644 --- a/django/db/models/deletion.py +++ b/django/db/models/deletion.py @@ -65,7 +65,7 @@ def get_candidate_relations_to_delete(opts): # N-N (i.e., many-to-many) relations aren't candidates for deletion. return ( f for f in candidate_model_fields - if f.auto_created and not f.concrete and (f.one_to_one or f.many_to_one) + if f.auto_created and not f.concrete and (f.one_to_one or f.one_to_many) ) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index c991945217..3ded406a6b 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1528,8 +1528,8 @@ class ManyToManyRel(ForeignObjectRel): class ForeignObject(RelatedField): # Field flags many_to_many = False - many_to_one = False - one_to_many = True + many_to_one = True + one_to_many = False one_to_one = False requires_unique_target = True @@ -1841,8 +1841,8 @@ class ForeignObject(RelatedField): class ForeignKey(ForeignObject): # Field flags many_to_many = False - many_to_one = False - one_to_many = True + many_to_one = True + one_to_many = False one_to_one = False rel_class = ManyToOneRel diff --git a/django/db/models/options.py b/django/db/models/options.py index 0b669de121..8920b5d86c 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -388,9 +388,9 @@ class Options(object): # and all the models may not have been loaded yet; we don't want to cache # the string reference to the related_model. is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many) - is_not_a_generic_relation = lambda f: not (f.is_relation and f.many_to_one) + is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many) is_not_a_generic_foreign_key = lambda f: not ( - f.is_relation and f.one_to_many and not (hasattr(f.rel, 'to') and f.rel.to) + f.is_relation and f.many_to_one and not (hasattr(f.rel, 'to') and f.rel.to) ) return make_immutable_fields_list( "fields", @@ -564,7 +564,7 @@ class Options(object): for field in fields: # For backwards compatibility GenericForeignKey should not be # included in the results. - if field.is_relation and field.one_to_many and field.related_model is None: + if field.is_relation and field.many_to_one and field.related_model is None: continue names.add(field.name) |
