I have a model which allows users to upload an .ics file to a calender field via the FileField.
However this is not required so some objects will have associated files, other will not. In my template I want to output different things depending on this. I thought this would work…
My view passes a all the model objects in a seminarData variable..
{% for seminars in seminarData %}
{% if seminars.calender %}
{{seminars.title}}
{{seminars.message}}
<a href="{{seminars.calendar.url}}"> Download .ICS File</a>
{% else %}
{{seminars.title}}
{{seminars.message}}
{% endif %}
{% endfor %}
But this doesn’t seem to work… Everything just goes straight to the else section even those objects with associated files in the calender field.
Could it becasue in my model I have
calendar = models.FileField(upload_to="/uploadedCal/", blank=True)
And I need to have null=True or something?
I played around inequality operators aswell with no luck… Thanks
Edit: I think the solution would be pretty straightforward I just can’t see it annoyingly!
Calendar is spelt incorrectly in your if statement 😉