How can I add a new instance, delete an instance, and update an instance of a model in one views.py ?
Currently I have views.py that looks like this:
class BHA_UpdateView(UpdateView):
template_name = 'bha_test.html'
model = BHA_List
pk_url_kwarg = 'pk_alt'
fields = '__all__'
I know that I can update a current model instance using form:
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" class='btn btn-primary' value="Submit">
</form>
But what if I want to do delete, create, and update on the same page? I'm not sure how to do if I want to add & delete & update a model instance in a single page.
Ideally, if a user clicks on Delete
, or Create
, Update
button on a page, a modal screen will show up, and within that modal screen the user will be able to do whatever thing he wants to do.
What should I do? Is it possible to inherit multiple CBV, like this: class BHA_UpdateView(UpdateView, CreateView, DeleteView):
? If not, what should I do?