DEV Community

Discussion on: Django inline formsets with Class-based views and crispy forms

 
katbotkowska profile image
KatBot

I can't use generic create view for add articles to task, because it doesn't work, so I used form view, update view works but only for that model m2m.
My other models m2m -add articles to contracts needs diffrent piece of code, I don't understand why, but solution for task doesn't work.

Thread Thread
 
mzakonek profile image
Mateusz

Thanks a lot! I will try to implement this in my project during this weekend and let you know how it goes.

And your EditArticlesInTaskFormSet is inlineformset or just modelformset_factory of TaskArticle ? Could you share it??
Once again, thanks a lot!

Thread Thread
 
katbotkowska profile image
KatBot

I didn't use inline formsets but model formset factory. I set I'd do it but with my data validations and fields querysets it was too complicated.

class EditArticlesInTaskForm(ModelForm):

def clean(self):
    super().clean()
    #many lines of code to validate accounting
        return self.cleaned_data

class Meta:
    model = TaskArticles
    fields = ('article', 'value')

EditArticlesInTaskFormSet = modelformset_factory(TaskArticles, fields=('article', 'value'),
extra=0, form=EditArticlesInTaskForm)

Thread Thread
 
mzakonek profile image
Mateusz

Now everything works, thanks so much!!!