How can I access the object passed by the user inside a generic view class?
In template, when the user clicks the link:
<td><a href="{% url 'update_peon' pk=item.pk %}"><button class="btn btn-warning">Edit</button></a></td>
this goes to urls.py:
url(r'^update_peon/(?P<pk>\d+)$', views.UpdatePeon.as_view(), name='update_peon'),
and my view:
class UpdatePeon(generic.UpdateView):
login_required = True
template_name = 'appform/Peons/peon_form.html'
model = Person
form_class = PersonForm
success_url = reverse_lazy('view_peons')
I would like to access the item.attr1
or at least item.pk
inside the class so I could change the model and form accordingly, something like:
class UpdatePeon(generic.UpdateView):
login_required = True
template_name = 'appform/Peons/peon_form.html'
if item['attr1'] == "Attribute1":
model = model1
form = model1Form
else:
etc
success_url = reverse_lazy('view_peons')
I know how to do it in a normal function based class or even if I rewrite a class based view from scratch but I don't want to do that.