The supplier field in contract is an instance of a Supplier object which is
not a string, so comparing it to a string won't work, instead compare a
field of the supplier instance in the supplier field in contract instance.
Like: {% if contract.supplier.name == "IBM"%}
Do you get it?
On Thu, Jan 12, 2023, 2:13 PM 'dtdave' via Django users <
[email protected]> wrote:
> I have the following relationship in a model
>
> class Contract(models.Model):
> supplier = models.ForeignKey(
> Supplier,
> on_delete=models.CASCADE,
> verbose_name="Supplier Name",
> related_name="contract_suppliers",
> )
>
> I am trying to include an if statement in my template but the following
> does not work:
> {% if contract.supplier == 'IBM' %}
>
> If I replace this with a non-foreign key item then it works fine.
>
> Any help would be appreciated.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4343a170-b193-4c91-aac4-8d773404353dn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4343a170-b193-4c91-aac4-8d773404353dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CADGG_A%3DMaFuX%2B%3DUM0xyyCud1E%3DkmMFOPFeZXih4fQvoYyfy5Kw%40mail.gmail.com.