[FIXED] How to customize Date and Time field in django forms?
Issue
How to customzie the default dateTime field in django forms to be more friendly to the user.
forms.py:
class new_album_form(forms.ModelForm):
class Meta:
model = album
fields = ['album_name', 'album_artist', 'released_at', 'price', 'is_approved']
and I am using the default django forms
<form method="post" novalidate>
{% csrf_token %}
{{form.as_p}}
<button type="submit" value="submit">Create</button>
</form>
Solution
—— form.py ———
class new_album_form(forms.ModelForm):
class Meta:
model = album
fields = ['album_name', 'album_artist', 'released_at', 'price', 'is_approved']
widgets = {
'released_at':forms.TextInput(attrs={'type':'datetime-local'}),
}
—— Output ——–
Answered By – Mahammadhusain kadiwala
Answer Checked By – Mary Flores (FixeMe Volunteer)