On 16/ago/2012, at 23:35, Houmie <hou...@gmail.com> wrote:

> The question might seem too simplistic, but it seems formsets can only work 
> with forms that have simple type fields such as charfield.
> But has anyone tried to use a form with a dropdown and use that form to 
> instantiate a formset?
> 
> Let me give you an example why this fails:
> 
> Model:
> 
> class SalesItem(models.Model):        
>     item_description    = models.CharField(max_length=40)
>     company             = models.ForeignKey(Company)
> 
> Here I create a form with a dropdown, hoping to pass in the company as a 
> source for the dropdown. Hold on to this thought, as I think that is not 
> possible in my scenario.
> 
> Form:
> 
> class SalesItemFSForm(Form):        
>     sales_item      =   forms.ModelChoiceField(required=False, queryset = '')
> 
>     def __init__(self, company, *args, **kwargs):
>         super(SalesItemFSForm, self).__init__(*args, **kwargs)
>         self.fields.sales_item.queryset = company.salesitem_set.all()
> 
> Now within my view I would like to create a formset with this form:
> 
> formset_type = formset_factory(SalesItemFSForm, extra=0)
> 
> The problem becomes right away clear, as there seem to be no way that I could 
> pass in the company to determine the source for the dropdown.
> 
> 
> How would you solve this please?
> 

Extend the model form set.


> Many Thanks,
> Houman
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/YGT3FYCdYbUJ.
> 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.

-- 
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