Dynamic form field type.
2012-08-05 22:09:25 GMT
Since what I was trying to do in this post : "Dynamic fieldsets on ModelAdmin"
seems to be a dead end, and I'm running out of wild ideas, i'm going to share
with u what I'm trying to do so you can maybe help me out.
I have three Models,
Home, HomeAttributeType and HomeAttributeValue. HomeAttributeValue has
an FK to HomeAttributeType and one to Home.
The idea is that the user can add as many HomeAttributeTypes as he wants and
set the data type of the former. ie :
ha1 = HomeAttributeType
ha1.name = 'FooAttr2'
ha1.type = 'boolean'
ha2 = HomeAttributeType
ha2.name = 'FooAttr2'
ha2.type = 'numeric'
So, now the user when creating a Home through a ModelAdmin, has the Admin
for the HomeAttributeValue inlined, and so he can set, for example, for that home
a FooAttr1 selecting in from the Drop Down menu.
And here comes the black magic, If he selects FooAttr1 the value field for the HomeAttributeValue
should render itself as radio button (yes/no) and if it where FooAttr2 it should render itself as
an InputText. I can easily do this with JS, but what I can't do is to somehow add a bunch
of hidden inputs that can relate each HomeAttributeType to what they should render to.
Since I have a variable number of HomeAttributeTypes, I need to set a variable number of
hidden fields in the form. I was reading about FormSets but I can't find the way to add one
to the ModelForm that the HomeAdmin is using.
Any help, hints, or even curses will be appreciated.
Lo unico instantaneo en la vida es el cafe, y es bien feo.
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.