Tuesday, March 20, 2018

Given a model, how can I get a widget for each field?

Pulling my hair out again.

I don't have a form, nor want a form, stunning really, but I just have the model. And I want the field widgets.

I can't seem to find them anywhere. I know you can specify widget= on form fields when declaring the model, but can't find it anywhere in the data structure.

Before you go asking why (really prefer some though invested into answer questions over questioning questions ;-), the need is simple enough. I have a list view, and at the top I want to put some filter options. So for selected fields in the model being listed, I want the widget to display at top along with operators. =, < > etc ... so I can filter the list view with some controls. But the filter needs the appropriate widget given a model field. Sort of model._meta.fields[n].widget, but not, as that doesn't work.

Of course I'm in a ListView when I need it, and so have access to it as well, but again can find no form or widgets there.

Spent so long searching doco and the web already I'm either blind (could be) or this is just bothersomely tricky!

Regards,

Bernd.

--
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+unsubscribe@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/9634d5a3-abbe-441a-9b34-bba896a36146%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment