Which Python and Django versions do you use?
Etienne
Le 2017-10-27 à 23:27, Paul Kenjora a écrit :
Hi,
When setting HiddenInput on a form widget for an integer model field
with choices, in tests I get 'X is not a valid choice' errors. I'm
guessing it's the hidden input returning a STRING and the model
expecting an INT.
I have a model that has....
*classBanner(models.Model):
*
*banner_x = models.PositiveIntegerField(blank=False, default=0,
choices=enumerate(BANNER_XS))*
*
*
And a form that has....
*classBannerForm(forms.ModelForm):*
*classMeta:*
*model = Banner*
*fields = ['banner_x']*
*def__init__(self, *args, **kwargs):*
*kwargs['prefix'] = 'banner'*
*super(BannerForm, self).__init__(*args, **kwargs)*
*self.fields['banner_x'].widget = forms.HiddenInput()*
In my unit tests I always get the error:
***resp = self.client.post(**'/banner/, {*
*'banner-banner_x':0,*
**
*}, follow=True)
*
*<ul class="errorlist"><li>banner_x<ul class="errorlist"><li>Select a
valid choice. 0 is not one of the available choices.</li></ul>*
*
*
Anyone else seeing this? Works fine via browser, just unit tests are
not coming back right.
--
- Paul Kenjora
- 602-214-7285
--
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto: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/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Etienne Robillard
tkad...@yandex.com
http://www.isotopesoftware.ca/
--
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/9ffccbba-aee5-0cbf-2819-823d3bf9efd1%40yandex.com.
For more options, visit https://groups.google.com/d/optout.