mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.8.x] 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.
Backport of 18c0aaa912 from master
This commit is contained in:
@@ -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)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1475,8 +1475,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
|
||||
@@ -1785,8 +1785,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
|
||||
|
||||
empty_strings_allowed = False
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user