Reputation: 73
I have a problem with my code here is template code:
{% for category in categorys %}
<p>
{{category.name}}
{% for gamename in gamenames %}
{% if gamename.category == category.name %}
{{gamename.title}}
{% else %}
b
{% endif %}
{% endfor %}
</p>
{% endfor %}
and here is model code:
class Category(models.Model):
name=models.CharField(max_length=200)
opis=models.TextField(max_length=600)
def __str__(self):
return self.name
class GameName(models.Model):
author = models.ForeignKey('auth.User')
category = models.ForeignKey('Category')
title = models.CharField(max_length=200)
created_date = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.title
and here is output screen:screen
i checked the gamename.category and is equal to category.name but if statement giving always "else"why when if statement should be true?
Upvotes: 0
Views: 54
Reputation: 6096
gamename.category
is a category
object, so try using gamename.category.name
inside the if statement instead.
Upvotes: 2