#24502: Using non model fields in an admin ModelForm does not work if the field
is
listed in fieldsets (and fields I think)
-------------------------------+--------------------------------------
Reporter: bdauvergne | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by bdauvergne):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I worked around the problem with this hack in my code:
{{{
@@ -188,16 +189,30 @@ class AuthenticUserAdmin(UserAdmin):
qs = models.Attribute.objects.filter(required=True)
insertion_idx = 1
if qs.exists():
fieldsets = list(fieldsets)
fieldsets.insert(insertion_idx,
(_('Attributes'), {'fields': [at.name for at in
qs]}))
return fieldsets
+ def get_form(self, request, obj=None, **kwargs):
+ if 'fields' in kwargs:
+ fields = kwargs.pop('fields')
+ else:
+ fields = flatten_fieldsets(self.get_fieldsets(request, obj))
+ if obj:
+ qs = models.Attribute.objects.all()
+ else:
+ qs = models.Attribute.objects.filter(required=True)
+ non_model_fields = [a.name for a in qs]
+ fields = list(set(fields) - set(non_model_fields))
+ kwargs['fields'] = fields
+ return super(AuthenticUserAdmin, self).get_form(request, obj=obj,
**kwargs)
+
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24502#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.c11ccf225f9cbf3c06f49f7439bf10a6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.