James, Did you ever get a response to this issue? I am having a devil of a time adding some extra non-model fields to an admin inline form. My added complication is that the fields are only defined at run time, so I have to have a loop that creates them based on a different model in my app.
Would you be willing to share your code with me? In particular, I am not sure where and how you are using self.form.declared_fields. I am running django 1.11. Thanks! Mark On Mon, Apr 30, 2018 at 1:41 AM, 'James Foley' via Django users < django-users@googlegroups.com> wrote: > So, I have a ModelAdmin that I need to add extra fields to. These fields > do not exist on the model, but will be dynamically added to a custom > ModelForm through the __init__ method, and logic inside clean will handle > the returned data on save. > > I can't seem to find any solid information related to adding custom > non-model fields to a ModelAdmin form. The closest I have come is by > overriding get_fields on the ModelAdmin class and updating > self.form.declared_fields with the new fields I'd like to add. > > This just doesn't feel very clean to me and I was curious if there was a > better way to add new fields to a ModelAdmin dynamically? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/a590e54f-1f36-497b-b508-cba339c5f2fc%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/a590e54f-1f36-497b-b508-cba339c5f2fc%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEqej2NFGCaTbL2%3Dp8mBGbQfYGqjM4RbRYE5WOxK90zZL-ArsA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.