From 326539f6a4936cda031b4a5f7caad788569f3329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sat, 16 Nov 2013 20:51:47 +0200 Subject: [PATCH] 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. --- django/forms/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/forms/models.py b/django/forms/models.py index 610a2a176a..9e8feb2ee9 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -179,7 +179,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): continue if fields is not None and not f.name in fields: