Reputation:
why is it i cant put value from my database to input type date? even though my query is correct?
{% for feedback in feedbacks %}
<input name="datef" value="{{feedback.dateSubmitted}}" type="date">
{% endfor %}
this is my views.py
feedback = obj.objects.all()
print(feedback)
this is the result for print
<QuerySet [<TrEmployeeSuppliersFeedbackQuestionsSubmittedRecords: mystudent>]>
my models.py
class TrEmployeeSuppliersFeedbackQuestionsSubmittedRecords(models.Model):
.....
dateSubmitted = models.DateField(auto_now_add=True, null=True, blank=True)
.....
the result in my webview
UPDATE: i change my html to this , and this is the result in my webview
html
{% for feedback in feedbacks %}
{{feedback.dateSubmitted}} <input name="datef" value="{{feedback.dateSubmitted}}" type="date">
{% endfor %}
Upvotes: 0
Views: 1622
Reputation: 1466
for all user inputs i think it will be better to use django forms or ModelForms after that django will format all values for you and it will be more cleaner way to validate user data, and save it to database. for multiple forms you can use formset
in view you create formset:
TrEmployeeSuppliersFeedbackQuestionsSubmittedRecordsFormSet = modelformset_factory(
TrEmployeeSuppliersFeedbackQuestionsSubmittedRecords,
fields=('dateSubmitted ', )
)
formset = TrEmployeeSuppliersFeedbackQuestionsSubmittedRecordsFormSet()
and add formset
as parameter to your html
template
and then in html template you can
{{ formset.management_form }}
{% for form in formset %}
{{ form.dateSubmitted.value }} {{ form.dateSubmitted }}
{% endfor %}
Upvotes: 0
Reputation: 6096
I suspect the formatting is off. The date input probably wants something like year-month-date
. Try passing it like this:
<input name="datef" value="{{feedback.dateSubmitted|date:'Y-m-d'}}" type="date">
If the above doesn't work, also try:
<input name="datef" value="{{feedback.dateSubmitted|date:'d/m/Y'}}" type="date">
Upvotes: 3