Created
January 3, 2013 01:12
-
-
Save anonymous/4439975 to your computer and use it in GitHub Desktop.
Just like the Django CBV CreateView, except allows population (and override) of the instance sent to the form
This file contains 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 InstanciatedCreateView(SingleObjectTemplateResponseMixin, ModelFormMixin, ProcessFormView): | |
template_name_suffix = '_form' | |
def get_object(self): | |
return self.model() | |
def get(self, request, *args, **kwargs): | |
self.object = self.get_object() | |
return super(InstanciatedCreateView, self).get(request, *args, **kwargs) | |
def post(self, request, *args, **kwargs): | |
self.object = self.get_object() | |
return super(InstanciatedCreateView, self).post(request, *args, **kwargs) | |
class OrderView(InstanciatedCreateView): | |
model = Order | |
def get_object(self): | |
return Order(user=self.request.user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment