Skip to content

Commit

Permalink
removing a is_gfk field flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PirosB3 committed Dec 21, 2014
1 parent 5f475e2 commit 3f66876
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _get_non_gfk_field(opts, name):
should be treated as not found by the 'label_for_field' function.
"""
field = opts.get_field(name)
if getattr(field, 'is_gfk', False):
if field.has_relation and field.one_to_many and not field.related_model:
raise models.FieldDoesNotExist()
return field

Expand Down
4 changes: 0 additions & 4 deletions django/contrib/contenttypes/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class GenericForeignKey(FieldFlagsMixin):
Provides a generic relation to any object through content-type/object-id
fields.
"""
# Adding a specific flag to identify GenericForeignKey without having to
# import base class and do instance check
is_gfk = True

related_model = None
editable = False
is_reverse_object = False
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def fields(self):
# these three filters as filters to the generator.
is_not_an_m2m_field = lambda f: not (f.has_relation and f.many_to_many)
is_not_a_generic_relation = lambda f: not (f.has_relation and f.many_to_one)
is_not_a_generic_foreign_key = lambda f: not hasattr(f, 'is_gfk')
is_not_a_generic_foreign_key = lambda f: not (f.has_relation and f.one_to_many and not f.related_model)

return make_immutable_fields_list("fields", (f for f in self.get_fields(reverse=False) if
is_not_an_m2m_field(f) and is_not_a_generic_relation(f)
Expand Down
7 changes: 4 additions & 3 deletions django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,10 @@ def names_to_path(self, names, opts, allow_many=True, fail_on_missing=False):
try:
field = opts.get_field(name)

# Fields like a GenericForeignKey cannot generate reverse relations
# therefore they cannote be used for reverse querying.
if hasattr(field, 'is_gfk'):
# Fields that contain one-to-many relations with a generic model (like a
# GenericForeignKey) cannot generate reverse relations Therefore they
# cannote be used for reverse querying.
if field.has_relation and not field.related_model:
raise FieldError("Field %r is a GenericForeignKey. This field "
"type does not generate a reverse relation "
"by default and therefore cannot be used for "
Expand Down

0 comments on commit 3f66876

Please sign in to comment.