Possible Bug Regarding model choices and form hidden input?

23 views
Skip to first unread message

Paul Kenjora

unread,
Oct 27, 2017, 11:28:27 PM10/27/17
to django...@googlegroups.com
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....

class Banner(models.Model):

  banner_x = models.PositiveIntegerField(blank=False, default=0, choices=enumerate(BANNER_XS))


And a form that has....

class BannerForm(forms.ModelForm):

  class Meta:

    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

Etienne Robillard

unread,
Oct 28, 2017, 9:02:48 AM10/28/17
to Paul Kenjora, django...@googlegroups.com

Which Python and Django versions do you use?

Etienne

--
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...@googlegroups.com.
To post to this group, send email to django...@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.
For more options, visit https://groups.google.com/d/optout.

-- 
Etienne Robillard
tka...@yandex.com
http://www.isotopesoftware.ca/

Paul Kenjora

unread,
Oct 28, 2017, 11:03:16 AM10/28/17
to Etienne Robillard, django...@googlegroups.com
I use:         

Django version 1.7.0 - I know I know :)

Python 2.7.13

- Paul


To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

Jani Tiainen

unread,
Oct 28, 2017, 2:09:39 PM10/28/17
to django...@googlegroups.com
Hi.

Unfortunately 1.7 is unsupported version. 

You should test with 1.11 to see if issue still exist.

Reply all
Reply to author
Forward
0 new messages