Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Forked from coderanger/admin.py
Created February 11, 2014 19:54
Show Gist options
  • Select an option

  • Save rochacbruno/8942815 to your computer and use it in GitHub Desktop.

Select an option

Save rochacbruno/8942815 to your computer and use it in GitHub Desktop.
class MyInline(admin.TabularInline):
model = MyModel
extra = 0
template = 'admin/edit_inline/list.html'
def get_formset(self, request, obj=None, **kwargs):
FormSet = super(ActivationKeyInline, self).get_formset(request, obj, **kwargs)
class NewFormSet(FormSet):
def _construct_forms(self, *args, **kwargs):
qs = self.get_queryset()
paginator = Paginator(qs, 20)
try:
page_num = int(request.GET.get('page', '1'))
except ValueError:
page_num = 1
try:
page = paginator.page(page_num)
except (EmptyPage, InvalidPage):
page = paginator.page(paginator.num_pages)
self.paginator = paginator
self.page = page
self._queryset = page.object_list
self.max_num = len(page.object_list)
return super(NewFormSet, self)._construct_forms(*args, **kwargs)
return NewFormSet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment