Eric Abrahamsen
unread,Mar 4, 2015, 12:40:40 AM3/4/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hi,
I'm making some heavily customized model formsets, to encourage my users
to input data. Mostly that involves cutting down the number of huge
drop-down menus they have to go surfing through.
So I have a model like this:
class Work(models.Model):
authors = models.ManyToManyField(Author,blank=True,related_name="works")
I first present them with a pre-query form, to choose an Author, then
give them a Work modelformset with the "authors" field pre-filled with
that author. So the initial data sort of looks like:
init["authors"] = [pre_query.cleaned_data["authors"]] # must be a list
for i in range(0, number_of_additional_forms):
initial.append(init)
formset = WorkFormSet(queryset=Work.objects.none(), initial=initial)
Nothing unusual there. Now I want to make the "authors" field hidden.
This is both to reassure my users, and to reduce the size of the page --
these are really long dropdowns.
Adding the hidden widget to the "authors" field, however, gives me this
validation error:
(Hidden field authors) Enter a list of values.
The form input field looks like this:
<input id="id_form-7-authors" name="form-7-authors" type="hidden" value="[37L]" />
Looks like a list of values to me, but maybe it's not getting read that
way.
In the meantime it's not a disaster if the monster "authors" dropdown is
visible for each of my Work forms, but it would be really nice to
eventually get it hidden.
In the past I did this by manually *removing* fields from the forms, and
adding the values in during the POST/save process, but that always felt
bad to me.
Thanks!
Eric