I’m implementing class based views in Django 1.3 and I find myself in this scenario where my CreateView, UpdateView and DeleteView are almost identical. Is there a way to implement this with only a single view CreateUpdateView or something like that or is this the standard way to implement CBGV’s?
Also, in ThingyAdd I haven’t specified the model like I have in ThingyEdit, yet they both function fine. I’m making the assumption that the model is implied/picked-up by the model defined in the meta portion of the form_class, ThingyForm, which is a ModelForm. Is this assumption correct?
class ThingyAdd(AuthMixin, CreateView):
form_class = ThingyForm
context_object_name='object'
template_name='change_form.html'
success_url='/done/'
class ThingyEdit(AuthMixin, UpdateView):
model = Thingy
form_class = ThingyForm
context_object_name='object'
template_name='change_form.html'
success_url='/done/'
class ThingyDelete(AuthMixin, DeleteView):
model = Thingy
form_class = ThingyForm
context_object_name='object'
template_name='delete_confirmation.html'
success_url='/done/'
You could create another mixin
Then in your views: