Skip to content

Instantly share code, notes, and snippets.

@sleekslush
Created January 6, 2012 06:42
Show Gist options
  • Save sleekslush/1569404 to your computer and use it in GitHub Desktop.
Save sleekslush/1569404 to your computer and use it in GitHub Desktop.
An example of extending UpdateView to use a formset instead of a form
class UserUpdateView(AuthenticatorViewMixin, UpdateView):
model = User
template_name = 'manager/authenticator/user_list.html'
def get_form_class(self):
return modelformset_factory(User, extra=0)
def get_form_kwargs(self):
kwargs = super(UserUpdateView, self).get_form_kwargs()
kwargs['queryset'] = kwargs['instance']
del kwargs['instance']
return kwargs
def get_object(self):
return self.get_queryset()
@dnoyes
Copy link

dnoyes commented Jan 7, 2012

Multiple inheritance. You like to live life dangerously.

@sleekslush
Copy link
Author

Don't look at it that way 😄

Treat it like a true mixin and all will be well in the world!

And BTW, the way python implements multiple inheritance is really smart and very powerful if used correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment