how to use a forloop such that the if the “IF” statement in the loop is satisfied the loop ends in Django...
I have 2 Django models Review
and Item
that I am working with. I want to see if the user has already reviewed the item. If yes he sees the review score. if no he sees the button to review the item
I have the below Review model
class Review (models.Model):
review_from = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_from')
review_for = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_for')
item = models.ForeignKey(OrderItem, related_name='items')
Defining the variables in the view context (pseudocode)
admin = User.objects.get(username="admin")
admins_reviews = Review.objects.filter(review_from__username = "admin")
Below is my template
{% for item in buyers_items %}
{% for review in buyers_review%}
{% if review.item.id == item.id %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">
<button>Leave Review</button>
</a>
{% endif %}
{% endfor %}
{% endfor %}
If I do this I get a below error
How can I overcome this problem.
View
from django import template
register = template.Library()
class OrderHistory(LoginRequiredMixin, ListView):
model = Order
template_name = 'order/order_list.html'
def get_context_data(self, **kwargs):
context = super(OrderHistory, self).get_context_data()
context['order_details'] = Order.objects.filter(emailAddress=self.request.user.email)
context['order_items'] = OrderItem.objects.filter(order__emailAddress=self.request.user.email)
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
print(context['buyers_review'])
return context
Custom Tag
@register.filter()
def review_bought_items(order_items, buyers_review):
return buyers_review.filter(item__in=order_items).exists()
django python-3.x django-templates django-views
|
show 4 more comments
I have 2 Django models Review
and Item
that I am working with. I want to see if the user has already reviewed the item. If yes he sees the review score. if no he sees the button to review the item
I have the below Review model
class Review (models.Model):
review_from = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_from')
review_for = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_for')
item = models.ForeignKey(OrderItem, related_name='items')
Defining the variables in the view context (pseudocode)
admin = User.objects.get(username="admin")
admins_reviews = Review.objects.filter(review_from__username = "admin")
Below is my template
{% for item in buyers_items %}
{% for review in buyers_review%}
{% if review.item.id == item.id %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">
<button>Leave Review</button>
</a>
{% endif %}
{% endfor %}
{% endfor %}
If I do this I get a below error
How can I overcome this problem.
View
from django import template
register = template.Library()
class OrderHistory(LoginRequiredMixin, ListView):
model = Order
template_name = 'order/order_list.html'
def get_context_data(self, **kwargs):
context = super(OrderHistory, self).get_context_data()
context['order_details'] = Order.objects.filter(emailAddress=self.request.user.email)
context['order_items'] = OrderItem.objects.filter(order__emailAddress=self.request.user.email)
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
print(context['buyers_review'])
return context
Custom Tag
@register.filter()
def review_bought_items(order_items, buyers_review):
return buyers_review.filter(item__in=order_items).exists()
django python-3.x django-templates django-views
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19
|
show 4 more comments
I have 2 Django models Review
and Item
that I am working with. I want to see if the user has already reviewed the item. If yes he sees the review score. if no he sees the button to review the item
I have the below Review model
class Review (models.Model):
review_from = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_from')
review_for = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_for')
item = models.ForeignKey(OrderItem, related_name='items')
Defining the variables in the view context (pseudocode)
admin = User.objects.get(username="admin")
admins_reviews = Review.objects.filter(review_from__username = "admin")
Below is my template
{% for item in buyers_items %}
{% for review in buyers_review%}
{% if review.item.id == item.id %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">
<button>Leave Review</button>
</a>
{% endif %}
{% endfor %}
{% endfor %}
If I do this I get a below error
How can I overcome this problem.
View
from django import template
register = template.Library()
class OrderHistory(LoginRequiredMixin, ListView):
model = Order
template_name = 'order/order_list.html'
def get_context_data(self, **kwargs):
context = super(OrderHistory, self).get_context_data()
context['order_details'] = Order.objects.filter(emailAddress=self.request.user.email)
context['order_items'] = OrderItem.objects.filter(order__emailAddress=self.request.user.email)
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
print(context['buyers_review'])
return context
Custom Tag
@register.filter()
def review_bought_items(order_items, buyers_review):
return buyers_review.filter(item__in=order_items).exists()
django python-3.x django-templates django-views
I have 2 Django models Review
and Item
that I am working with. I want to see if the user has already reviewed the item. If yes he sees the review score. if no he sees the button to review the item
I have the below Review model
class Review (models.Model):
review_from = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_from')
review_for = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='review_for')
item = models.ForeignKey(OrderItem, related_name='items')
Defining the variables in the view context (pseudocode)
admin = User.objects.get(username="admin")
admins_reviews = Review.objects.filter(review_from__username = "admin")
Below is my template
{% for item in buyers_items %}
{% for review in buyers_review%}
{% if review.item.id == item.id %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">
<button>Leave Review</button>
</a>
{% endif %}
{% endfor %}
{% endfor %}
If I do this I get a below error
How can I overcome this problem.
View
from django import template
register = template.Library()
class OrderHistory(LoginRequiredMixin, ListView):
model = Order
template_name = 'order/order_list.html'
def get_context_data(self, **kwargs):
context = super(OrderHistory, self).get_context_data()
context['order_details'] = Order.objects.filter(emailAddress=self.request.user.email)
context['order_items'] = OrderItem.objects.filter(order__emailAddress=self.request.user.email)
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
print(context['buyers_review'])
return context
Custom Tag
@register.filter()
def review_bought_items(order_items, buyers_review):
return buyers_review.filter(item__in=order_items).exists()
django python-3.x django-templates django-views
django python-3.x django-templates django-views
edited Nov 25 '18 at 23:23
Lemayzeur
5,3201834
5,3201834
asked Nov 25 '18 at 22:05
MarcoBianchiMarcoBianchi
21612
21612
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19
|
show 4 more comments
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19
|
show 4 more comments
2 Answers
2
active
oldest
votes
Based on what I see in your templates, you could do it simpler with a tag filter or in your view side. Let's go with a custom tag:
@register.filter
def review_bought_items(buyers_items,buyers_review):
return buyers_review.filter(item__in=buyers_items).exists()
Now in the templates you could do
<!-- load the tag -->
{% load file %}
{% if buyers_items|review_bought_items:buyers_review %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">Leave Review</a>
{% endif %}
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
|
show 2 more comments
The issue is that you are iterating over all buyers_reviews
. In this particular case, you have 2 buyer reviews, one for the current item and one for a different one.
First iteration will evaluate to False
the first condition and it will display all the Leave Review
button and the 2nd iteration will evaluate it to True
and display the "Your rating" block.
If you don't want to move all the logic on the backend, maybe make us of a template tag in order to filter the reviews based on item.id
I tried to filter it in the views currently my views arecontext['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the itemcontext['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work
– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472476%2fhow-to-use-a-forloop-such-that-the-if-the-if-statement-in-the-loop-is-satisfie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Based on what I see in your templates, you could do it simpler with a tag filter or in your view side. Let's go with a custom tag:
@register.filter
def review_bought_items(buyers_items,buyers_review):
return buyers_review.filter(item__in=buyers_items).exists()
Now in the templates you could do
<!-- load the tag -->
{% load file %}
{% if buyers_items|review_bought_items:buyers_review %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">Leave Review</a>
{% endif %}
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
|
show 2 more comments
Based on what I see in your templates, you could do it simpler with a tag filter or in your view side. Let's go with a custom tag:
@register.filter
def review_bought_items(buyers_items,buyers_review):
return buyers_review.filter(item__in=buyers_items).exists()
Now in the templates you could do
<!-- load the tag -->
{% load file %}
{% if buyers_items|review_bought_items:buyers_review %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">Leave Review</a>
{% endif %}
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
|
show 2 more comments
Based on what I see in your templates, you could do it simpler with a tag filter or in your view side. Let's go with a custom tag:
@register.filter
def review_bought_items(buyers_items,buyers_review):
return buyers_review.filter(item__in=buyers_items).exists()
Now in the templates you could do
<!-- load the tag -->
{% load file %}
{% if buyers_items|review_bought_items:buyers_review %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">Leave Review</a>
{% endif %}
Based on what I see in your templates, you could do it simpler with a tag filter or in your view side. Let's go with a custom tag:
@register.filter
def review_bought_items(buyers_items,buyers_review):
return buyers_review.filter(item__in=buyers_items).exists()
Now in the templates you could do
<!-- load the tag -->
{% load file %}
{% if buyers_items|review_bought_items:buyers_review %}
<button class="text-success">Your rating<br/><b>{{review.ratings}}/10</b></button>
{% else %}
<a href="{% url ... %}">Leave Review</a>
{% endif %}
edited Nov 25 '18 at 22:58
answered Nov 25 '18 at 22:51
LemayzeurLemayzeur
5,3201834
5,3201834
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
|
show 2 more comments
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
working on this now
– MarcoBianchi
Nov 25 '18 at 22:57
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
I have edited my views (see question above) as per your code does that look correct to you.
– MarcoBianchi
Nov 25 '18 at 23:17
1
1
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
No @SamirTendulkar it's not correct, the custom tag should be a separated file, take a look here to see how to write a custom tag
– Lemayzeur
Nov 25 '18 at 23:19
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
did it work for you @SamirTendulkar?
– Lemayzeur
Nov 25 '18 at 23:52
1
1
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
Ok glad to help!
– Lemayzeur
Nov 26 '18 at 0:06
|
show 2 more comments
The issue is that you are iterating over all buyers_reviews
. In this particular case, you have 2 buyer reviews, one for the current item and one for a different one.
First iteration will evaluate to False
the first condition and it will display all the Leave Review
button and the 2nd iteration will evaluate it to True
and display the "Your rating" block.
If you don't want to move all the logic on the backend, maybe make us of a template tag in order to filter the reviews based on item.id
I tried to filter it in the views currently my views arecontext['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the itemcontext['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work
– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
add a comment |
The issue is that you are iterating over all buyers_reviews
. In this particular case, you have 2 buyer reviews, one for the current item and one for a different one.
First iteration will evaluate to False
the first condition and it will display all the Leave Review
button and the 2nd iteration will evaluate it to True
and display the "Your rating" block.
If you don't want to move all the logic on the backend, maybe make us of a template tag in order to filter the reviews based on item.id
I tried to filter it in the views currently my views arecontext['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the itemcontext['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work
– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
add a comment |
The issue is that you are iterating over all buyers_reviews
. In this particular case, you have 2 buyer reviews, one for the current item and one for a different one.
First iteration will evaluate to False
the first condition and it will display all the Leave Review
button and the 2nd iteration will evaluate it to True
and display the "Your rating" block.
If you don't want to move all the logic on the backend, maybe make us of a template tag in order to filter the reviews based on item.id
The issue is that you are iterating over all buyers_reviews
. In this particular case, you have 2 buyer reviews, one for the current item and one for a different one.
First iteration will evaluate to False
the first condition and it will display all the Leave Review
button and the 2nd iteration will evaluate it to True
and display the "Your rating" block.
If you don't want to move all the logic on the backend, maybe make us of a template tag in order to filter the reviews based on item.id
answered Nov 25 '18 at 22:26
AlexAlex
48439
48439
I tried to filter it in the views currently my views arecontext['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the itemcontext['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work
– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
add a comment |
I tried to filter it in the views currently my views arecontext['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the itemcontext['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work
– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
I tried to filter it in the views currently my views are
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the item context['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work– MarcoBianchi
Nov 25 '18 at 22:39
I tried to filter it in the views currently my views are
context['buyers_review'] = Review.objects.filter(review_from=self.request.user)
I am not sure how to filter the item context['buyers_review'] = Review.objects.filter(review_from=self.request.user, item=self.kwargs.get("item"))
did not work– MarcoBianchi
Nov 25 '18 at 22:39
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
I don't know how your full view looks like but, you could use the solution recommended in the comments section and create a custom filter (docs.djangoproject.com/en/2.1/howto/custom-template-tags) and apply it in template rather than comparing item ids.
– Alex
Nov 25 '18 at 22:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472476%2fhow-to-use-a-forloop-such-that-the-if-the-if-statement-in-the-loop-is-satisfie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's not clear what error you're getting?
– Jon Clements♦
Nov 25 '18 at 22:07
@JonClements I have edited the image. I am getting 2 buttons one with the review and one that says leave review. See above image. SInce they both have reviews.
– MarcoBianchi
Nov 25 '18 at 22:12
All these logic must be done in your back-end, not in the template side. Show your view, so I can help
– Lemayzeur
Nov 25 '18 at 22:17
If you c/p the html template, you have a typo at the {% endif %} tag.
– Alex
Nov 25 '18 at 22:18
@Alex I fixed it is correct in the actual code
– MarcoBianchi
Nov 25 '18 at 22:19