formsets

Paginate Django formset

梦想与她 提交于 2019-11-30 05:36:39
I have a model formset that I want to display 10 forms at a time using Django's Paginator, but it can't be done like paginator = Paginator(formset, 10) . What's the correct way to do this, if there is a way? Filly This is a generic example of the solution I found to my problem: In the forms.py file: class MyForm(ModelForm): class Meta: model = MyModel fields = ('description',) In the views.py file: from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger FormSet = modelformset_factory(MyModel, form=MyForm, extra=0) if request.method == 'POST': formset = FormSet(request.POST,

Paginate Django formset

梦想的初衷 提交于 2019-11-29 03:37:54
问题 I have a model formset that I want to display 10 forms at a time using Django's Paginator, but it can't be done like paginator = Paginator(formset, 10) . What's the correct way to do this, if there is a way? 回答1: This is a generic example of the solution I found to my problem: In the forms.py file: class MyForm(ModelForm): class Meta: model = MyModel fields = ('description',) In the views.py file: from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger FormSet = modelformset

How would you make a dynamic formset in Django?

半城伤御伤魂 提交于 2019-11-28 16:07:27
Here's the way I'm doing it: {{ formset.management_form }} <table> {% for form in formset.forms %} {{ form }} {% endfor %} </table> <a href="javascript:void(0)" id="add_form">Add Form</a> And here's the JS: var form_count = {{formset.total_form_count}}; $('#add_form').click(function() { form_count++; var form = '{{formset.empty_form|escapejs}}'.replace(/__prefix__/g, form_count); $('#forms').append(form) $('#id_form-TOTAL_FORMS').val(form_count); }); What specifically bothers me is that I had to write that escapejs template tag myself. It just strips all newlines and escapes any single quotes