Created
January 6, 2012 06:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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
Multiple inheritance. You like to live life dangerously.