My payment attribute has a ForeignKey relation. In my accounts.html, I want to show users if they have paid for their orders. So I was trying it like this:
{% if order.payment is null or blank %}
<td> x</td>
{% else %}
<td> Yes</td>
{% endif %}
But it didn't work out. What is the proper code for this?
My orders.models.py:
class Order(models.Model):
payment = models.ForeignKey(Payment, on_delete=models.SET_NULL, blank= True, null=True)
My accounts.html:
{% for order in user.order_set.all %}
<tbody>
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td>{{ order.order_id }}</td>
{% if order.payment is null or blank %}
<td> x</td>
{% else %}
<td> Yes</td>
{% endif %}
<td>No</td>
</tr>
</tbody>
{% endfor %}
You can simply use {% if not order.payment %}
, and I'm pretty sure you can also use {% if not order.payment.exists %}
, or {% if order.payment is None %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With