Answers for "mixin in django"

0

django deleteview class

##### views.py #####
from django.urls import reverse_lazy
from django.views.generic.edit import DeleteView
from myapp.models import Author

class AuthorDelete(DeleteView):
    model = Author
    success_url = reverse_lazy('author-list')
    
##### author_confirm_delete.html #####
<form method="post">{% csrf_token %}
    <p>Are you sure you want to delete "{{ object }}"?</p>
    <input type="submit" value="Confirm">
</form>
Posted by: Guest on April-17-2020
-1

django updateview class

###### views.py #####
from .models import Article
from .forms import  UpdateArticleForm
from django.views.generic import UpdateView
class ArticleUpdateView(UpdateView):
    model = Article
    form_class = UpdateArticleForm
    template_name = 'articles/create_article.html'
    
###### urls.py  ######
from .views import ArticleUpdateView
urlpatterns =[ 
  path('articles/<int:pk>/update/', ArticleUpdateView.as_view()),]
# pk is default value (for primary key of id of an instance of object
Posted by: Guest on April-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language