Also thank you for informing me to include less. I put 3 files there because i thought someone would have needed it.
I wasn't clear enough. You should include the *entire code* that reproduces the problem. Remove stuff from your code until you can't remove any more, while the problem is still there.


On 14/04/2022 05.57, 'Delvin Alexander' via Django users wrote:
test func is a function that my 'User' passes tests mixins runs in django.

Also thank you for informing me to include less. I put 3 files there because i thought someone would have needed it.

On Tue, Apr 12, 2022 at 11:20 PM Antonis Christofides <[email protected]> wrote:

    What is `test_func()`?

    In addition, if you want people to help you, it would be a good idea to
    help them by giving them the smallest possible amount of code that
    reproduces the problem. (In fact, whenever I do that, in about 50% of
    cases I solve the problem myself during the reduction process.)

    Regards,

    Antonis


    On 13/04/2022 07.32, 'Delvin Alexander' via Django users wrote:

    Hello everyone,

    i am having trouble. i created a delete button but my page does not
    confirm the deletion of the post, nor does it redirect to another page.
    may someone help guide me on what it is i have done wrong and explain for
    me please?

    - I feel as though the problem could be located in my views.py but not sure


    Here is my views.py:

    *from django.shortcuts import render*
    *from django.contrib.auth.mixins import LoginRequiredMixin,
    UserPassesTestMixin*
    *from django.views.generic import ListView, DetailView, CreateView,
    UpdateView, DeleteView*
    *from .models import Post*
    *

    *
    *def home(request):*
    *    context = {*
    *        'posts': Post.objects.all()*
    *    }*
    *    return render(request, 'blog/home.html', context)*
    *

    *
    *class PostListView(ListView):*
    *    model = Post*
    *    template_name = 'blog/home.html'*
    *    context_object_name = 'posts'*
    *    ordering = ['-date_posted']*
    *

    *
    *class PostDetailView(DetailView):*
    *    model = Post*
    **
    **
    *class PostCreateView(LoginRequiredMixin, CreateView):*
    *    model = Post*
    *    fields = ['title', 'content']*
    **
    *    def form_valid(self, form):*
    *        form.instance.author = self.request.user*
    *        return super().form_valid(form)*
    **
    *class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):*
    *    model = Post*
    *    fields = ['title', 'content']*
    **
    *    def form_valid(self, form):*
    *        form.instance.author = self.request.user*
    *        return super().form_valid(form)*
    **
    *    def test_func(self):*
    *        post = self.get_object()*
    *        if self.request.user == post.author:*
    *            return True*
    *        return False*
    **
    *class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):*
    *    model = Post*
    *    success_url = 'blog'*
    **
    *    def test_func(self):*
    *        post = self.get_object()*
    *        if self.request.user == post.author:*
    *            return True*
    *        return False*
    *
    *
    *def about(request):*
    *    return render(request, 'blog/about.html', {'title': 'About'})*
    *
    *
    *
    *
    *
    *
    Here is my urls.py:

    *from django.urls import path*
    *from .views import PostListView, PostDetailView, PostCreateView,
    PostUpdateView, PostDeleteView*
    *from . import views*
    *
    *
    *urlpatterns = [*
    *    path('', PostListView.as_view(), name='blog-home'),*
    *    path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),*
    *    path('post/new/', PostCreateView.as_view(), name='post-create'),*
    *    path('post/<int:pk>/update/', PostUpdateView.as_view(),
    name='post-update'),*
    *    path('post/<int:pk>/delete/', PostDeleteView.as_view(),
    name='post-delete'),*
    *    path('about/', views.about, name='blog-about'),*
    *]*


    And here is my post_confirm_delete.html:

    *{% extends "blog/base.html" %}*
    *{% block content %}*
    *    <div class="content-section">*
    *            {% csrf_token %}*
    *            <fieldset class="form-group">*
    *                <legend class="border-bottom mb-4">Delete Post</legend>*
    *                <h2>Are you sure you want to delete this post? "{{
    object.title }}"</h2>*
    *            </fieldset>*
    *            <div class="form-group">*
    *                <button class="btn btn-outline-danger"
    type="submit">Yes, Delete</button>*
    *                <a class="btn btn-outline-secondary" href="{% url
    'post-detail' object.id <http://object.id> %}">Cancel</a> *
    *            </div>*
    *        </form>*
    *    </div> *
    *{% endblock content %}*


-- You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to [email protected].
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/3a23eabf-f8bd-4fa3-a27b-199a3aabf33bn%40googlegroups.com
    
<https://groups.google.com/d/msgid/django-users/3a23eabf-f8bd-4fa3-a27b-199a3aabf33bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
-- You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to [email protected].
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/b1d616eb-7460-8263-f1ad-74efb59c64d8%40antonischristofides.com
    
<https://groups.google.com/d/msgid/django-users/b1d616eb-7460-8263-f1ad-74efb59c64d8%40antonischristofides.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADq-sifgaQERmPb0M-agMGX2GchWJ_vHPjBnzzjj9njz7BnW5Q%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CADq-sifgaQERmPb0M-agMGX2GchWJ_vHPjBnzzjj9njz7BnW5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a7f8d8b-0da2-6212-3db5-461e8ab6d8f0%40antonischristofides.com.

Reply via email to