RE: value for choices arguments for newforms.MultipleSelectField
Hi Peter, > What should I pass as a dummy queryset parameter: this is positional > mandatory argument and I cannot pass None. If you're going to replace it before you render the form, it really doesn't matter - any queryset will do. I used .objects.all(), but that has the disadvantage of actually querying the database for a list that I then throw away when I change the queryset. I see that the trunk now has .none(), which is probably perfect for this situation. If you're using 0.96, though, the ideal is probably some queryset that you know will return no (or very few) objects. Chris --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: value for choices arguments for newforms.MultipleSelectField
On 8/7/07, Chris Brand <[EMAIL PROTECTED]> wrote: > self.fields[f].queryset = queryset > # Have to force the widget to update itself (bug 4787) > self.fields[f].widget.choices = self.fields[f].choices Hi Chris, thanks for your help - it solved my problem, but another one has arised: What should I pass as a dummy queryset parameter: this is positional mandatory argument and I cannot pass None. Is it correct if I pass queryset = _QuerySet() Thanks, Peter --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
RE: value for choices arguments for newforms.MultipleSelectField
> def my_view(request): > > class MyForm(forms.Form) > emails = forms.ModelMultipleChoiceField(queryset= > MyDBModel.objects.filter(user=request.user.id) > > > But I'd like to have form declaration out of this view na pass user's > ID as an argument - is there any way how to supply queryset in > runtime? I tried to assign queryset later to form's instance having no > success. If ModelMultipleChoiceField behaves the same as ModelChoiceField, you'll have to explicitly set the choices on the widget, too. Here's an extract from my code : self.fields[f].queryset = queryset # Have to force the widget to update itself (bug 4787) self.fields[f].widget.choices = self.fields[f].choices http://code.djangoproject.com/ticket/4787 doesn't mention ModelMultipleChoiceField, so if you do need to do this, you should probably update the ticket to say so. Chris --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: value for choices arguments for newforms.MultipleSelectField
On 2 Srp, 17:35, Nathan Ostgard <[EMAIL PROTECTED]> wrote: > You can use ModelMultipleChoiceField for this: > > items = > newforms.ModelMultipleChoiceField(queryset=Items.objects.all()) Hi Nathan, I use it this way, but I need to reduce the queryset for current user whom ID is contained in HTTP request. I'm a beginner, hence I implemented it by nesting form's declaration into view function: def my_view(request): class MyForm(forms.Form) emails = forms.ModelMultipleChoiceField(queryset= MyDBModel.objects.filter(user=request.user.id) But I'd like to have form declaration out of this view na pass user's ID as an argument - is there any way how to supply queryset in runtime? I tried to assign queryset later to form's instance having no success. Thanks, Peter --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: value for choices arguments for newforms.MultipleSelectField
Hi, On 8/3/07, james_027 <[EMAIL PROTECTED]> wrote: > I don't see ModelMultipleChoiceField on the documentaion or the latest > source code You can look at http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/tests.py till the documenation is updated. > Thanks > james Kai --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: value for choices arguments for newforms.MultipleSelectField
H On Aug 2, 11:35 pm, Nathan Ostgard <[EMAIL PROTECTED]> wrote: > You can use ModelMultipleChoiceField for this: > > items = > newforms.ModelMultipleChoiceField(queryset=Items.objects.all()) > I don't see ModelMultipleChoiceField on the documentaion or the latest source code Thanks james --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: value for choices arguments for newforms.MultipleSelectField
You can use ModelMultipleChoiceField for this: items = newforms.ModelMultipleChoiceField(queryset=Items.objects.all()) On Aug 2, 1:24 am, james_027 <[EMAIL PROTECTED]> wrote: > hi > > somewhere on the django documentation I saw the choice provided for > MultipleSelectField is from a Database but I can't recall where I read > it but I do it this way, let me know if there are better alternative > > items = newforms.MultipleChoiceField(choices = [('i.id', 'i.name') for > i in Items.objects.all()]) > > Thanks > james --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
value for choices arguments for newforms.MultipleSelectField
hi somewhere on the django documentation I saw the choice provided for MultipleSelectField is from a Database but I can't recall where I read it but I do it this way, let me know if there are better alternative items = newforms.MultipleChoiceField(choices = [('i.id', 'i.name') for i in Items.objects.all()]) Thanks james --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---