DEV Community

Django inline formsets with Class-based views and crispy forms

Xenia on February 13, 2019

Recently I used inline formsets in one of my Django projects and I liked how it worked out very much. I decided to share my example of integration ...
Collapse
 
mzakonek profile image
Mateusz • Edited

Thanks a lot for your post! I am facing a problem at using the inline formset in the same way that you described, but at the manytomany relation.
Let's assume that the Language is a separated Model. Now I want to create inline formset between Collection and CollectionTitle:

class Language(models.Model):
    name = models.CharField(max_length=3)


class Collection(models.Model):
    subject = models.CharField(max_length=300, blank=True)
    owner = models.CharField(max_length=300, blank=True)
    note = models.TextField(blank=True)
    created_by = models.ForeignKey(User,
        related_name="collections", blank=True, null=True,
        on_delete=models.SET_NULL)

    titles_with_language = models.ManyToManyField(Language, through="CollectionTitle", related_name='collections')

    def __str__(self):
        return str(self.id)


class CollectionTitle(models.Model):

    collection = models.ForeignKey(Collection, related_name="has_titles", on_delete=models.CASCADE)
    language = models.ForeignKey(Language, related_name='titles', on_delete=models.CASCADE)
    name = models.CharField(max_length=500, verbose_name="Title")
Enter fullscreen mode Exit fullscreen mode

I updated forms and verything is displayed properly, I can add/remove CollectionTitles, but when I hit submit, form is always invalid. I can't find the reason why... Can someone help me/give advice what should I look at or what am I doing wrong?

Collapse
 
katbotkowska profile image
KatBot

It could be a problem with your views or forms. Paste that code. I've faced the similiar problem with formsets for m2m trought table and generic views maybe I can help you.

Collapse
 
nad2000 profile image
Radomirs Cirskis

adding the manytomany fields to the excluded field list solved this issue:

class CollectionTitleForm(forms.ModelForm):

    class Meta:
        model = CollectionTitle
        exclude = ["titles_with_language"]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mzakonek profile image
Mateusz • Edited

Hi,
I am sending link to code: github.com/mzakonek/laboratory_app...
It will open the Cart app in my project and inline formset is implemented at the 'views.py' and 'forms.py' files.
Actually I don't even need those 'remove' or 'add' buttons in the form. I need only to update the fields in the form.
Thanks a lot for your time!

Thread Thread
 
katbotkowska profile image
KatBot

I have a project concerning budget managing with model task, articles (expenditure category) and model m2m task_articles. Here, you have my code for create, update view for m2m model:

add articles to task

class AddArticlesToTaskView(PermissionRequiredMixin, FormView):
permission_required = 'budget.add_taskarticles'
raise_exception = False
login_url = reverse_lazy('budget:login')
permission_denied_message = 'You dont\'t have permission to add articles to task'
template_name = 'budget/add_articles_to_task.html'
pk_url_kwarg = 'task_slug'
success_url = ''

def get_task(self):
    task_slug = self.kwargs.get('task_slug')
    return Task.objects.get(slug=task_slug)

def get_form_class(self):
    return formset_factory(AddArticlesToTaskForm, extra=6)

def get_success_url(self):
    return reverse('budget:task_details', kwargs={'task_slug': self.kwargs.get('task_slug')})

def form_valid(self, form):
    for single_form in form:
        instance = single_form.save(commit=False)
        instance.task = self.get_task()
        instance.save()
    return super().form_valid(form)

def get_context_data(self, **kwargs):
    ctx = super().get_context_data(**kwargs)
    ctx['task'] = self.get_task()
    return ctx

class EditArticlesInTaskView(PermissionRequiredMixin, UpdateView):
permission_required = 'budget.change_taskarticles'
raise_exception = False
login_url = reverse_lazy('budget:login')
permission_denied_message = 'You dont\'t have permission to edit articles to task'
model = TaskArticles
form_class = EditArticlesInTaskForm
template_name = 'budget/task_edit_articles.html'
slug_url_kwarg = 'task_slug'
success_url = ''

def get_object(self, queryset=None):
    return self.get_task()

def get_queryset(self):
    return TaskArticles.objects.filter(task=self.get_task())

def get_task(self):
    task_slug = self.kwargs.get('task_slug')
    return Task.objects.get(slug=task_slug)

def get_success_url(self):
    return reverse('budget:task_details', kwargs={'task_slug': self.kwargs.get('task_slug')})

def post(self, request, *args, **kwargs):
    self.object = self.get_object()
    formset = EditArticlesInTaskFormSet(request.POST)
    if formset.is_valid():
        return self.form_valid(formset)
    return self.form_invalid(request, formset)

def form_invalid(self, request, formset):
    return render(request, self.template_name, {"formset": formset})

def form_valid(self, form):
    for single_form in form:
        instance = single_form.save(commit=False)
        instance.task = self.get_task()
        instance.save()
    return super().form_valid(form)

def get_context_data(self, **kwargs):
    ctx = super().get_context_data(**kwargs)
    ctx['task'] = self.get_task()
    ctx['formset'] = EditArticlesInTaskFormSet(queryset=TaskArticles.objects.filter(task=self.get_task()))
    return ctx

I hope it would help you. If you need more code, write :)

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

Collapse
 
mzakonek profile image
Mateusz

Or if you could share snippet with your implementation for m2m, then it will also be very helpful.

Collapse
 
andi1337 profile image
Andreas • Edited

Hey Xenia,

thank you for this helpful post. That's exactly what I was looking for. I've applied a small modification to make your solution a bit more crispy ;-)

Instead of putting all the form layout stuff into the file formset.html it would a better solution to add a LayoutHelper to the CollectionTitleForm:

forms.py

from django import forms
from .models import Collection, CollectionTitle
from django.forms.models import inlineformset_factory
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field, Fieldset, Div, Row, HTML, ButtonHolder, Submit
from .custom_layout_object import Formset

import re


class CollectionTitleForm(forms.ModelForm):

    class Meta:
        model = CollectionTitle
        exclude = ()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        formtag_prefix = re.sub('-[0-9]+$', '', kwargs.get('prefix', ''))

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Row(
                Field('name'),
                Field('language'),
                Field('DELETE'),
                css_class='formset_row-{}'.format(formtag_prefix)
            )
        )


CollectionTitleFormSet = inlineformset_factory(
    Collection, CollectionTitle, form=CollectionTitleForm,
    fields=['name', 'language'], extra=1, can_delete=True
)


class CollectionForm(forms.ModelForm):

    class Meta:
        model = Collection
        exclude = ['created_by', ]

    def __init__(self, *args, **kwargs):
        super(CollectionForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = True
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-md-3 create-label'
        self.helper.field_class = 'col-md-9'
        self.helper.layout = Layout(
            Div(
                Field('subject'),
                Field('owner'),
                Fieldset('Add titles',
                         Formset('titles')),
                Field('note'),
                HTML("<br>"),
                ButtonHolder(Submit('submit', 'Save')),
            )
        )
Enter fullscreen mode Exit fullscreen mode

Then you can simplify your formset.html

{% load crispy_forms_tags %}
{% load staticfiles %}

<style type="text/css">
  .delete-row {
    align-self: center;
  }
</style>

{{ formset.management_form|crispy }}

{% for form in formset.forms %}
  {% for hidden in form.hidden_fields %}
    {{ hidden|as_crispy_field }}
  {% endfor %}
  {% crispy form %}
{% endfor %}

<br>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="{% static 'mycollections/libraries/django-dynamic-formset/jquery.formset.js' %}"></script>
<script type="text/javascript">
    $('.formset_row-{{ formset.prefix }}').formset({
        addText: 'add another',
        deleteText: 'remove',
        prefix: '{{ formset.prefix }}',
    });
</script>
Enter fullscreen mode Exit fullscreen mode

The advantage is that the layout is now modified by crispy_forms applying the selected template pack (e.g. bootstrap4). Only the CSS .delete-row must be secified to center the remove button of the django-formset plugin because only a link is added if the containing element is not a HTML-table.

Best regards,
andi

Collapse
 
zxenia profile image
Xenia

Thanks for your contribution! I merged it into a new branch :)

Collapse
 
asma_sehli_2ddf4a418ee5a4 profile image
Asma Sehli

thank you all for the whole code. but my "remove" item is not working :( I tried all solutions with no result :'(

Collapse
 
jmplourde profile image
Jean-Michel Plourde

I really appreciated your article! I was looking at the terrible django-crispy doc, trying to also understand djang formset and I was at lost. Then I randomly stumbled on your article and everything clicked in. You resumed everything in a very educational way what others couldn't explain through pages of very unhelpful explanations. Thank you!

Collapse
 
zxenia profile image
Xenia

Thank you very much!

Collapse
 
iaminarush profile image
iaminarush • Edited

Hey thanks a ton for this tutorial, im still quite new to django so I was wondering how would I go about adding a validation so at least one CollectionTitle is required for each Collection, thanks alot!

Collapse
 
iaminarush profile image
iaminarush

So I've figured out how to add validation for the CollectionTitle, but im doing it through views.py. Wondering if anybody knows how to add the validation to client side instead of going through views, thanks.

How I am doing it at the moment is adding a min_num and validate_min to the inlineformset_factory.

forms.py

CollectionTitleFormSet = inlineformset_factory(
    Collection, CollectionTitle, form=CollectionTitleForm,
    fields=['name', 'language'], can_delete=True, min_num=1, validate_min=True, extra=0
    )

And by setting an else function in the form_valid. I save the object after validating titles since my project requires at least one title for each collection.

views.py

class CollectionCreate(CreateView):
#kept rest the same till form_valid

def form_valid(self, form):
        context = self.get_context_data()
        titles = context['titles']
        with transaction.atomic():
            form.instance.created_by = self.request.user
            if titles.is_valid():
                self.object = form.save()
                titles.instance = self.object
                titles.save()
            else:
                context.update({'titles': titles})
                return self.render_to_response(context)
        return super(CollectionCreate, self).form_valid(form)
Collapse
 
ramialloush profile image
Rami Alloush • Edited

Great code! have been looking all day :/
This works for me

    def form_valid(self, form):
        context = self.get_context_data()
        subunits = context['subunits']
        with transaction.atomic():
            if subunits.is_valid():
                self.object = form.save()
                subunits.instance = self.object
                subunits.save()
                return super(UnitCreateView, self).form_valid(form)
            else:
                return self.render_to_response(self.get_context_data(form=form))
Collapse
 
gbritoo27 profile image
Gonçalo Brito

Hello!

How would you do this if you had another "inline_formset" inside of each title?
This should be done using nested formsets but you had to basically do the same thing you did for the titles but inside each title.

Does that make sense to you?

Hit me up with your thoughts.

Cheers,

Collapse
 
zxenia profile image
Xenia • Edited

Hi Gonçalo,

Thanks for the question!
You are right, you will need to use nested form inside each form in formset.
For this you need to create CollectionTitleChildFormSet and pass it in add_fields() method when overriding BaseInlineFormSet. Therefore the CollectionTitleFormSet will look different because now we need to set formset explicitly to BaseTitleChildFormset (check out my commit and this blog post).
The backend logic works fine for me but I didn't figure out how to implement dynamic 'add child': it should work like this - everytime I add a new Title the row with an empty Title and a row with at least One Child followed by button 'add child' is added.
If you figure it out I will be interested to know how ;)

Collapse
 
gbritoo27 profile image
Gonçalo Brito

Thanks for the quick reply!

I have my backend working as well. I believe that the jQuery library (django-dynamic-formset) is not prepared for this.
What you're doing with this library on the nested formsets is creating 1 formset with all the childs, and I believe this should create 1 formset with the childs on each title.
I also think your childs' prefix is wrong, let me know what prefix appears on the class when you use "formset_child-(( formset.prefix ))". I'm personally using formset_child-(( nested_form.prefix )) and it joins the formset (title) prefix with the childs' prefix, something like title-0-child-0, title-0-child-1.

I will spend the rest of the day trying to fix this, I'll let you know how it goes.

Collapse
 
orcaer profile image
orcaer • Edited

Hi Xenia and public,

I just implemented this but cant figure out why I'm getting "remove" buttons for each field of the formset. Also I can't customize the "Add another" or "delete" texts of the buttons. I have attached a photo of my result. Anyone any idea?
thepracticaldev.s3.amazonaws.com/i...

Collapse
 
mmcc5678 profile image
H

Did you find a solution to this? I have tried different versions of jquery.formset.js and am having the same result.

Zxenia, do you have any comment on why this would be the case?

Collapse
 
diophantus7 profile image
diophantus7

Had the same problem. Looks like it is a problem of newer versions of jquery.formset.js. Just download the one from the repo

Collapse
 
cryptedx profile image
crypted

Hey,

thank you for your great tutorial. This helped me a lot. I want to modify it because I want a table layout in my inline formsets. For this I am trying to use

"helper.template = 'bootstrap/table_inline_formset.html'
Enter fullscreen mode Exit fullscreen mode

from here: django-crispy-forms.readthedocs.io...

I tired every possibility which I have found on the internet. Among other things this stackoverflow.com/questions/217549...

But it is not working. What would be an proper way to implement it in your code from this tutorial?

Thank you in advance.

Collapse
 
richardbalwane profile image
Richard Balwane

Hello Xenia, thank you for this post. It is the closest I've come to solvingmy problem in a week! Am working on a project where I want Users to upload up to 3 images for each post they make. So, I need your CollectionTitle model to have just the foreign key field to the Post model and the image field with at least 1 image. Am using Crispy forms and CBVs with LoginRequiredMixin and UserPassesTestMixins. Any help would be much appreciated.

Collapse
 
mustafamond profile image
Mustafamond

Thanks again for your post it was a great help! I am having trouble with validation of the formset, though - if the main form does not have any errors but one of the forms in the formset does, the form still submits as if there were no errors, the main form saves, but the formset does not. Validation errors in the formset do not get displayed. In the CreateView, the form_valid method is as follows:

def form_valid(self, form):
        context = self.get_context_data()
        titles = context['titles']
        with transaction.atomic():
            form.instance.created_by = self.request.user
            self.object = form.save()
            if titles.is_valid():
                titles.instance = self.object
                titles.save()
        return super(CollectionCreate, self).form_valid(form)

It checks if titles is valid, but does nothing if titles is not valid. Would this be the place to add an else:?

if titles.is_valid():
    save the data
else:
   refresh the form showing errors in the formset

Or does that logic belong earlier in the form processing flow?

Thank you for any ideas on how to resolve this.

Collapse
 
ameykelekar profile image
AmeyKelekar

Hey Xenia,

Could you please help me with the following situation:
Assume your model CollectionTitle now have 1 more field
user = models.ForeignKey(User, on_delete=models.CASCADE)

Now, any user can add title and language.
When a user enters title and language and submits the form, auto-save the user field to the currently logged in user.

For example, User A created a new Collection. Now, User B and User C can add titles for this new created Collection. When user B adds a title and language, the user should be auto-saved to this entry along with the title and language.

Thanks in advance for all the support and help.

Regards,
Amey Kelekar

Collapse
 
soulscribbler profile image
Jeremy Collier

I'm having trouble getting the form to display both the formset fields and the regular form fields. Currently, the template is only displaying the formset fields.

I think I've narrowed it down to something I didn't do right in either the custom_layout_object.py or the formset.html.

I know that's vague, but any advice/tips on what I might need to change from your example to work with my project?

Collapse
 
soulscribbler profile image
Jeremy Collier

I figured out both the problems I was having! The first one (above) I had improperly configured the self.helper.layout div so it didn't know what to display! Everything seems to be working now in terms of the basic setup.

I was wondering though if you could advise me on how to make the form look better? I've messed with the formset.html but can't seem to figure out where to put formatting to make it look nice.

This is what my form currently looks like:

Collapse
 
widg3tt profile image
widg3tt

Thank you for this helpful post! I was able to get this working in my project with relative ease. Does anyone know of a quick fix for the bootstrap datepicker not working in a datetime field in the formset?

Collapse
 
unknown9421 profile image
Hoàng • Edited

I did like you. But it was not working. Somebody can help me.

==================================================================
class CompanyEdit(UpdateView):
model = Company
form_class = CompanyForm
template_name = 'frontend/company/createdit.html'
context_object_name = 'company'
success_message = 'Company Information Updated!'

def get_context_data(self, **kwargs):
    context = super(CompanyEdit, self).get_context_data(**kwargs)
    if self.request.POST:
        context['pictures'] = CompanyPictureFormSet(self.request.POST, self.request.FILES, instance=self.object)
    else:
        context['pictures'] = CompanyPictureFormSet(instance=self.object)
    return context

def form_valid(self, form):
    # update_instace = form.save(commit=False)
    context = self.get_context_data()
    pictures = context['pictures']
    with transaction.atomic():
        form.instance.created_by = self.request.user.username
        self.object = form.save()
        pictures.instance = self.object
        if pictures.is_valid():   # This is always return False.
            print(pictures.instance)
            pictures.save()
Collapse
 
jarlmorgennebel profile image
JarlMorgennebel

Hey Xenia,

thank you for sharing your solution, this looks awesome and is extremely helpful.

I have a use-case of 7 categories which each may have 1-7 detail lines. My goal is a Bootstrap4-Accordion group (getbootstrap.com/docs/4.0/componen...) to switch between the 7 categories and use your solution for the each of detail-lines groups as a single page - start with 2 extra lines and allow up to 7 maximum.

Can you please push me into the right direction how I could adopt your solution and modify it to support 7 formfactory_inline fields (one per category)?

My first attempts failed big and I am only a few months into Django.

Thanks, -MN

Collapse
 
st0ked56 profile image
Michael

Thank you for the example. This works great!

What would be the best way to wrap the formset fields in a DIV? I have in the helper.Layout the below logic.

        Fieldset('Logistics',
                 Formset('logistics')
                 ),
Enter fullscreen mode Exit fullscreen mode

I would like to Div('Formset_field', css_class="", data-toggle="", etc.)

Collapse
 
dantgo profile image
Daniel Gore

Thanks again for this.

I have a FileField as part of my Formset, which when added to the ModelForm is displayed correctly and allows for file selection, but when saved, the file is not uploaded to the model. I think this is something todo with 'request.FILES' not existing in the View I'm just not sure how to rewrite it to include it.

Can anyone help?

Collapse
 
widg3tt profile image
widg3tt

I was able to get this working flawlessly with the CreateView. I am having an issue with the UpdateView though. I cannot get the related items to update although there are no errors or issues thrown anywhere when submitted. Thank you

Collapse
 
sachin179 profile image
Sachin Singh

Can you please share how to do the same thing without using crispy forms?
I have tried to do the same and createview is working fine but in UpdateView unable to save the changes made in inline_formset. It save the data when adding new line.
please help me out.

Collapse
 
zxenia profile image
Xenia • Edited

Hi Sachin,

To implement it without crispy forms check out this blog, the solution is not using crispy forms. The UpdateView is essentially the same as CreateView except you need to pass instance (instance=self.object) in get_context_data() because the instance already exists in the database (the code part for this is here ). Hope it helps!

Collapse
 
elisa55516883 profile image
elisa

Haiiii,

I got some bug in this code.please help me to find out.The bug is

ValueError: Cannot assign ">": "Collection.created_by" must be a "User" instance.

Collapse
 
andi1337 profile image
Andreas • Edited

Hey elisa,

I think you have to call localhost:8000/admin and log in as user "admin" and password "admin". If you take a look into the classes CollectionCreate or CollectionUpdate inside views.py then you can see that the created_by field is always set to the user who executed the request. And the variable request.user is only set, if a user is logged in.

Hope that will help you to get the demo running ;-)
Best regards,
andi

Collapse
 
antsh85 profile image
antsh85

Super useful code, thank you!

Collapse
 
mvitsor profile image
Vitor Sternlicht

Hi @zxenia, thanks a lot for the post. Do you have an idea how one could nest a third model and edit all three models at the same time? Using your example with Collections and Titles, suppose that additionally every Title had multiple Editions; so I would want to keep the form as we have it, but add the ability to add/remove/edit Editions under each of the titles. Tks

Collapse
 
mustafamond profile image
Mustafamond • Edited

This was a great post and easy to follow - did exactly what I needed. However, I am having a problem on the validation side. I am unable to get any validation errors to show up on fields in the the formset. If the data in any field in the formset is not valid (forms.ValidationError raised using the form's clean method), or if the formset itself is not valid (for example, unique_together violated in the rows to be added), the overall form still posts and is the data is saved to the database, but the formset is simply ignored - nothing is saved and the form never chows the errors and the user never has a chance to correct any incorrect data.

Validation works correctly on the main form, just not the formset inserted using the Crispy layouts.

Any hints on how to get validation errors to cause the form to display the errors for the formset and subform during the post would be greatly appreciated.

Thanks for the great post!

Collapse
 
cfox4ever profile image
ethan roman

Thank you very much great post , much appreciated

Collapse
 
kingraphaii profile image
Percival Rapha

Thank you so much for this tut. How can i limit the number of forms in the form set that can be added?

Collapse
 
zxenia profile image
Xenia

Thanks!
When you create you inline formset you can limit the number of forms in the formset with max_num parameter

e.g.

CollectionTitleFormSet = inlineformset_factory(
    Collection, CollectionTitle, form=CollectionTitleForm,
    fields=['name', 'language'], extra=1, max_num=3, can_delete=True
    )
Collapse
 
k3nj1g profile image
k3nj1g

Thank you so much! You saved my day... no, a WEEK

Collapse
 
jeremih256 profile image
jeremih256

hey, Django-dynamic-formsets appears to be based on Django==1.7.1. Is there a way that I can implement this method using Django==3.#

Collapse
 
mattcarp12 profile image
Matt Carpenter

The models Collection and CollectionTitle made the code difficult to follow. I suggest choosing more distinct names to make it easier.

Collapse
 
rob101 profile image
rob101

Hi! Thanks Xenia. A quick question - why do you use with transaction.atomic(): in your form_valid() function?

Collapse
 
marcorichetta profile image
Rich

Hi!

That guarantees the transaction's atomicity, which is a database property.
Take a look at the explanation in Django docs

Collapse
 
nhatrang profile image
NhaTrang

Hello,

Would you have an idea on this issue? stackoverflow.com/q/66101476/13613237

Many Thanks

Collapse
 
nhatrang profile image
NhaTrang

Hello, how can we display the lines now in the html file?

Collapse
 
golimaarbhejeme profile image
AgnosticIndian!!!

There is something missing about the usage of the jquery plugin. I do not see the 'add' and remove' buttons added to the html at my end.

Collapse
 
marlonleite profile image
Marlon • Edited

The jquery add and remove buttons works only if there set a context['formset'] name. I do not know why. Maybe django 2 version or needs change the class Formset(LayoutObject)

So its works:

forms.py:

Fieldset(
'Add videos',
Formset('formset'),
),

views:

context['formset'] = PostVideoFormSet( self.request.POST, instance=self.object)

but if change this name to:

Fieldset(
'Add videos',
Formset('videos'),
),
and context['videos'] = PostVideoFormSet( self.request.POST, instance=self.object)

the buttons add and remove disappear

Collapse
 
razilator profile image
Vladislav

Xenia, how to save current user for child formset, when saving it doesn't save?

Collapse
 
sasikumar1978k profile image
sasikumar1978k

TypeError: Formset.render() missing 1 required positional argument: 'context'

Collapse
 
stevesmith0722 profile image
Steve Smith

Formsets are great! However, I've noticed recently they can be time consuming to retrieve when performing updates on them. Has anyone else encountered this issue?

Collapse
 
juliazanon profile image
juliazanon

Nothing wrong, just want to thank you so much for this, helped me a lot!

Collapse
 
juliazanon profile image
juliazanon

actually, I do have a problem.
Imagine you create a collection and add some titles. When you try to update that same collection, it doesn't seem to be able to remove the titles you added before. At least in my program, when I enter the update page, only forms for new titles show up, and not the old ones. What do I need to do to fix this problem?

Collapse
 
sasikumar1978k profile image
sasikumar1978k

is there any better and updated code to Django inline formsets with Class-based views and crispy forms