Hey Mark,

I've not actually found a solution yet, I've just sort of put it at the 
bottom of my pile of problems...

Here is the post that I used to get where I 
am https://stackoverflow.com/a/35797311/3173119

It just doesn't feel very Django like, and I feel that there must be an 
easier way to simply add a non-model field to a model admin form. My fields 
are also added at run time which is whats causing me issues.

My actual goal is to convert a flat JSON string stored in a JSON field, 
into fields for each key. Then once saved it coverts them all back into a 
JSON string and stored them back on the one JSON field.

James.

On Wednesday, 2 May 2018 16:02:51 UTC+1, mark wrote:
>
> 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...@googlegroups.com <javascript:>> 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...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> 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/9889680c-d447-4217-bc37-fc394772b512%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to