Reputation: 13
Want to extract the month and year from template
template_1.html
<form method = 'POST'>
<input type ='month' name = 'searchmonth'>
<input type = 'submit' value = 'Search'>
</form>
template_2.html
{% for i in record %}
{% if i.record_patient_number == number %}
{{ month = i.record_date.getMonth() }}
{% if month == searchrecordmonth %}
*something*
{% endif %}
{% endif %}
{% endfor %}
All variable are include in views.py
In this search month is not able to extract and record_date is save in models.py and as a
record_date = models.DateField(blank = True , null = True)
Upvotes: 0
Views: 583
Reputation: 2368
You cannot set values while in django template, your code below is invalid
{{ month = i.record_date.getMonth() }}
to get the month, simply get it from the i.record_date
{% if i.record_date.month == searchrecordmonth %}
Upvotes: 1