Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.6.x] Fixed a regression caused by fix for #21428

On Python 3 sorting Fields mixed with GenericForeignKeys doesn't work
as GenericForeignKey isn't a subclass of django.db.models.fields.Field.

Refs #21428.

Backport of 326539f from master
  • Loading branch information...
1 parent 1fd762c commit cbf8784d206819e83c43d75b422af51209c4b74c @akaariai akaariai committed
Showing with 5 additions and 1 deletion.
  1. +5 −1 django/forms/
6 django/forms/
@@ -173,7 +173,11 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
field_list = []
ignored = []
opts = model._meta
- for f in sorted(opts.concrete_fields + opts.virtual_fields + opts.many_to_many):
+ # Avoid circular import
+ from django.db.models.fields import Field as ModelField
+ sortable_virtual_fields = [f for f in opts.virtual_fields
+ if isinstance(f, ModelField)]
+ for f in sorted(opts.concrete_fields + sortable_virtual_fields + opts.many_to_many):
if not getattr(f, 'editable', False):
if fields is not None and not in fields:

0 comments on commit cbf8784

Please sign in to comment.
Something went wrong with that request. Please try again.