I want to show message based on my filter.
CHOICES = (
('0', 'published',),
('1', 'pending',),
('2', 'rejected',),
)
Here I tried this code for showing message based on filter but it’s only showing the published message.
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
published = BlogComment.objects.filter(is_published="0")
pending = BlogComment.objects.filter(is_published="1")
if published:
messages.add_message(self.request, messages.INFO, 'Comment status published Sucessfully')
elif pending:
messages.add_message(self.request, messages.INFO, 'Comment status pending Sucessfully')
return data
why I am only getting the published message?
I also tried if statement instead of elif. After using if statement I am getting three message at time while changing status of any object.
if published:
messages.add_message(self.request, messages.INFO, 'Comment Published Sucessfully')
if pending:
messages.add_message(self.request, messages.INFO, 'Comment Status Pending')
if rejected:
messages.add_message(self.request, messages.INFO, 'Comment Status Rejected')
I aslo tried to use pk in filter but didn’t work.
BlogComment.objects.filter(is_published="0", pk=True)