On Mon, Oct 24, 2011 at 6:30 PM, Carl Meyer <carl.j.me...@gmail.com> wrote:

> Hi,
>
> On Oct 24, 10:53 am, Kayode Odeyemi <drey...@gmail.com> wrote:
> > I'm sorry but it doesn't just seem to work for me. I have tried
> >
> > possibilities like:
> >
> > self.fields['branch_name'].choices =
> > Branch.objects.all().values('name_branch', 'name_branch')
> > self.fields['branch_name'].choices =
> > Branch.objects.all().values('name_branch')
>
> I don't think you've read Tom's responses carefully. You're still
> trying to use ".values()" here, resulting in a ValuesQuerySet which
> returns dictionaries instead of a regular QuerySet which returns model
> objects. That simply won't ever work. And that is the reason for the
> "need more than one value to unpack" error; it has to do with the
> format of the results returned, nothing to do with how many results
> are returned by the query.
>
> Thanks Carl.

I was able to resolve it with this:

class TransactionUpdateForm(forms.ModelForm):
    branch_name = ChoiceField(required=True)
    def __init__(self, *args, **kwargs):
        super(TransactionUpdateForm, self).__init__(*args, **kwargs)
        br = [obj.name_branch for obj in Branch.objects.all()]
        pos = [b for b in range(len(br))]
        self.fields['branch_name'].choices = zip(pos, br)

Thanks Tom


-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to