Dynamic Form Widget [django admin]

133 views
Skip to first unread message

Jon Walsh

unread,
Jul 14, 2010, 10:51:09 AM7/14/10
to Django users
Hi guys,

This might be best explained by example... for the following model:

class Setting(models.Model):
data_type = models.CharField()
value = models.TextField()

I want Django's admin to display a different form widget for the
"value" field depending on the input of "data_type". For example: if
"data_type" was "date", then the value field would use a date widget
instead of the TextField's default widget.

My predicament is that ModelAdmin is defined as a class, and not
instances. So I can't pass it a custom form since instances (i.e.
"data_type" value) are needed to decide what field the form should
have...

Any help would be greatly appreciated!

thanks, Jon

Laszlo Antal

unread,
Jul 14, 2010, 11:50:26 AM7/14/10
to django...@googlegroups.com
Hi,


If I understand you good how about using javascript to check what kind of info you enter into the data_type field and it would update the value input field. Using jquery it would be very easy to implement.

lzantal
 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Reply all
Reply to author
Forward
0 new messages