'selecting some form inputs and show it to the user
I want to be able to select only required fields and show it to my frontend, this is the html template. create_employee.html
{% for field in form %}
<div class="form-group{% if field.errors %} invalid{% endif %}">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="row">
<div class="col-6">
{{ field }}
</div>
</div>
{% for error in field.errors %}
<p class="help-block">{{ error }}</p>
{% endfor %}
</div>
{% endfor %}
I did something like {{ field.first_name }} but this does not show first name form input but if I use {{ field }} all the fields are shown up even the ones I don't want the user to see.
How can I select only the fields I want to return to the user?
forms.py
class EmployeeForm(BSModalModelForm):
class Meta:
model = EmployeeModel
fields = "__all__"
views.py
class CreateEmployeeView(BSModalCreateView):
template_name = 'payrolls/create_employee.html'
form_class = EmployeeForm
success_message = 'Success: Employee created'
success_url = reverse_lazy('payrolls:all_employees')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
