after defining form field when I try to access in django template using {{form.Date_Joined}}
not working
class UserAdd(forms.ModelForm):
class Meta:
model=CompanyUsers
fields= '__all__'
exclude=['usrPsswd','usrId','usrCmpnyId','lstLogin','is_active','usrDOJ']
widgets={
'Date_Joined':forms.DateInput(attrs={'type':'date'}),
}
The widget i’ve declare not showing
<div class="order">
<!-- <div class="head" > -->
<h4> ADD COMPANY</h4>
<!-- </div> -->
<table id="table-datas">
<form method="POST" action="">
{% csrf_token %}
<tbody>
<tr><td>Username</td><br><td>{{ form.usrNme}}</td></tr>
<tr><td>First Name </td><br><td>{{ form.usrFNme}}</td></tr>
<tr><td>Last Name </td><br><td>{{ form.usrLNme}}</td></tr>
<tr><td>Date of join</td><br><td>{{form.Date_Joined}}</td></tr>
<tr><td>Department</td><br><td>{{ form.usrDpt}}</td></tr>
<tr><td>Email</td><br><td>{{ form.usrMail}}</td></tr>
<tr><td><button type="submit">Register</button></td></tr>
</form>```
so the Date Joined field shows nothing
2
Answers
The
type
of theattrs
is not taken into account, this originates from theinput_type
of the widget, you thus create a custom widget:then we plug this in as widget:
I think you make a mistake with the typo field of the form
Date_Joined
because python is case sensitive.Type
Instead of