Ich habe ein Modell mit ContentType-Feld drin.Django ContentType und String-Vergleich
In jedem Modell Methode kann ich es auf den String vergleichen:
self.content_type == "construction" # True if ContentObject points to Construction model.
Allerdings ist eine solche Sache nicht in Vorlagen zu funktionieren scheint.
Das erste, was ich versuchte
{% if object.content_type == "construction" %}
Und zweitens:
def __unicode__(self):
return str(self.content_type)
`{% if object == "construction" %}`
und es ist falsch, aber {{object}} druckt construction
.
Versuchen Sie: '{% if object.content_type.model ==" construction "%}' –