Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2013 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4439975 to your computer and use it in GitHub Desktop.
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
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