Trouble with (unwanted) field validation

28 views
Skip to first unread message

DJ-Tom

unread,
Oct 30, 2013, 5:47:34 AM10/30/13
to django...@googlegroups.com
Hi,

given the following model field:

room_setup = models.ForeignKey("roomsetup", verbose_name='Default room setup', blank=True, null=True, default='')

In the modelform __init__ method I'm setting the choices for this field like this:

        self.fields['room_setup'].choices = roomsetups_as_choices(subevt)

def roomsetups_as_choices(subevt):
    rs = [['', '-----']]
    for setup in roomsetup.objects.filter(Q(subevent__isnull=True) | Q(subevent=subevt)):
        rs.append([setup.id, setup.name])

    return rs

When adding a new record I keep getting the following validation message, but only for the first try to submit of the form:

"Select a valid choice. That choice is not one of the available choices."

It passes without error on the second try... I really don't understand why?

IMHO it should not complain at all...

Any ideas?

Thomas

DJ-Tom

unread,
Nov 8, 2013, 7:29:31 AM11/8/13
to django...@googlegroups.com
I still didn't get this to work... isn't there anybody that is able to help?

Sergiy Khohlov

unread,
Nov 8, 2013, 7:41:49 AM11/8/13
to django-users
answer is simple . Validator would like to check field which is
used for Key. Look like this field is not set before validation.
I would like take a look at model form and part of code before form.is_valid
Many thanks,

Serge


+380 636150445
skype: skhohlov
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d6ff282b-aafa-411a-a5f6-00f6b6687e7a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.

DJ-Tom

unread,
Nov 11, 2013, 9:35:01 AM11/11/13
to django...@googlegroups.com

This is really weird - I just tried again and *can't* reproduce it at all ... everything is suddenly working as expected.

Thanks anyways ;-)
Reply all
Reply to author
Forward
0 new messages