Sunday, June 24, 2018

Re: how to pass the current user in reverse_lazy()

Thanks much!

On Sun, 24 Jun 2018, 5:50 pm Daniel Ale, <danielale9291@gmail.com> wrote:
Great. 

On Sun, Jun 24, 2018, 13:18 Saloni Kalra <salonikalra1999@gmail.com> wrote:
Yes it did! Thanks much!

On Sunday, 24 June 2018 17:14:31 UTC+5, Daniel Ale wrote:
Override the get_success_url(self) instead... That will work 

On Sun, Jun 24, 2018, 07:13 Saloni Kalra <salonik...@gmail.com> wrote:
DeleteView:

class DeletePost(LoginRequiredMixin, SelectRelatedMixin, generic.DeleteView):
    username = self.object.user.username
    model = models.Post
    select_related = ("user","teacher","subject")
    success_url = reverse_lazy("posts:for_user", kwargs={'username': self.request.user.username},)

    def get_queryset(self):
        queryset = super().get_queryset()
        return queryset.filter(user_id=self.request.user.id)

    def delete(self, *args, **kwargs):
        messages.success(self.request, "Post Deleted")
        return super().delete(*args, **kwargs)

Error in terminal:

username = self.object.user.username
NameError: name 'self' is not defined

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMO5YAqQCfk6P2r2J4e3XZz3Cznvbh970DArbrt33ZbpTEWbXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0fae669d-ee42-410b-b195-b035e5536ba1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALZOSo0F-LwNthhxYZtbs9tPDwG4N6htx0zBufSm0f3pC5GRFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMO5YAoETW27H8G4pz%3D1jdrOmCirUfp3Zn%2BD91zdfmQ7Wtkg%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment