Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use two formset in extra-views? #194

Open
sangramrajekakade opened this issue Jun 18, 2019 · 1 comment
Open

How to use two formset in extra-views? #194

sangramrajekakade opened this issue Jun 18, 2019 · 1 comment

Comments

@sangramrajekakade
Copy link

sangramrajekakade commented Jun 18, 2019

I am working on style properties and style option form both are different formset how I manage two formset in one view i am trying with this view but

Calling modelformset_factory without defining 'fields' or 'exclude' explicitly is prohibited.
this error show


class StylePropsUpdateViews(ModelFormSetView):
    model = StyleProps
    prop_form= StylePropsForm
    option_form = StylesOptionForm
    template_name="master/styleprops_form.html"
    def get_queryset(self):
        pk = self.kwargs.get('pk')
        current_user = self.request.user
        return self.model.objects.filter(ProductName=pk, user=current_user)

    def get_success_url(self):
        return reverse("tailoringproducts")

    def formset_valid(self, prop_form, option_form):
    	  for docs_form in prop_form:
    	  	  docs_form.save(commit=False)
    	  	  docs_form.instance.ProductName_id = self.kwargs.get('pk')
    	  	  docs_form.instance.user = self.request.user
    	  	  docs_form.save()
    	  	  messages.success(self.request, "Styling Properties Updated successfully")
    	  	  return HttpResponseRedirect(self.get_success_url())

    def formset_invalid(self, prop_form, option_form):
        messages.error(self.request, "Form getting invalid")
        return self.render_to_response(self.get_context_data(prop_form=prop_form, option_form=option_form))

see in this image I have option button after clicking on the options button option form will open

Screenshot from 2019-06-18 17-11-32

Screenshot from 2019-06-18 17-11-43

each style option form row has its own option form

can anyone help me in this

@sdolemelipone
Copy link
Collaborator

sdolemelipone commented Dec 18, 2019

The probable reason for the error is that you did not define fields, exclude or a form_class which had fields/exclude set in it's meta when you defined StylePropsUpdateViews. The below might have fixed that. I cannot help with the other problems as it looks like you are using a bespoke setup with multiple forms per object in the queryset.

class StylePropsUpdateViews(ModelFormSetView):
    model = StyleProps
    form_class = StylePropsForm
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants