Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi, We can't solve all of your problems for you :) But that being said - in the get_context_data you don't have a parameter for the request, however in all CBV you get the request as a variable on the CBV itself - so change: post.is_liked = post.likes.filter(user=request.user).exists() To: pos

Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
still showing the same error On Wednesday, May 13, 2020 at 2:34:03 PM UTC-4, Yamen Gamal Eldin wrote: > > I haven't seen any definition for user within ur function, so > Change this > post.is_liked = post.likes.filter(user=user).exists() > > To this > > post.is_liked = post.likes.filter(user=req

Re: How to over ride the get context data method in view

2020-05-13 Thread Yamen Gamal Eldin
I haven't seen any definition for user within ur function, so Change this post.is_liked = post.likes.filter(user=user).exists() To this post.is_liked = post.likes.filter(user=request.user).exists() Le mer. 13 mai 2020 à 19:22, Ahmed Khairy a écrit : > Hi There, > > I have rewritten the get_co

Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
Hi There, I have rewritten the get_context_data method to be like this but I am getting name 'user' is not defined: class PostListView(ListView): model = Post template_name = "score.html" ordering = ['-date_posted'] context_object_name = 'posts' paginate_by = 5 def get

Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi again, Bare with me - this is just written in this email - so: 1. Your listview is paginated by 5, so it will only show 5 posts - that's good for this exercise and how I would solve it. 2. Rewrite your get_context_data method to iterate over the posts: def get_context_data(self, **kwargs):

Re: How to over ride the get context data method in view

2020-05-13 Thread Ahmed Khairy
Hi Andréas Kühne, Regarding the first error I have a list of posts in the listView and want to add the like button to each post so how should I fix it? Thank you On Wednesday, May 13, 2020 at 6:08:31 AM UTC-4, Andréas Kühne wrote: > > Hi, > > There are a couple of errors in your code: > > 1.

Re: How to over ride the get context data method in view

2020-05-13 Thread Andréas Kühne
Hi, There are a couple of errors in your code: 1. You are using a ListView and then trying to get an individual post? That is really strange 2. In your get_context_data method - you first get the context data, update it and then you set it to a new dict, so everything is reset in the dict. 3. you

How to over ride the get context data method in view

2020-05-12 Thread Ahmed Khairy
I am currently trying to create a like button for my posts in Django I have reached to the part where I can add a like but I am facing difficulty writing the code related to the view which linking the PostListView if there is user who liked it or not. I am getting an error: page Error 404 alt