Using django-dynamic-formset with CreateWithInlinesView from django-extra-views - multiple formsets

前端 未结 1 781
面向向阳花
面向向阳花 2020-12-25 08:49

I got 3 models:

class Client(models.Model):
     first_name = models.CharField(max_length=20)
     last_name = models.CharField(max_length=40)

class Phone(m         


        
相关标签:
1条回答
  • 2020-12-25 09:28

    Oh my head ... I figured it out:

    {% block extra_footer_script %}
    <script type="text/javascript">
           $(function() {
               {% for formset in inlines %}
               $('div#FormSet{{ formset.prefix }}').formset({
                   prefix: '{{ formset.prefix }}',
                   formCssClass: 'dynamic-formset{{ forloop.counter }}'
               });
               {% endfor %}
           })
       </script>
    {% endblock %}
    

    If you see any errors please point them to me. Also appreciate any better ideas.

    For those who want to use this - Yes it should work with any number of formsets

    0 讨论(0)
提交回复
热议问题