Django-filter: style selection
I created a django filter to do column filtering on django-table2, BUT I still cannot create the generated dropdown to match the general page style
-I am using Bootsrap3
Please post any suggestion to resolve this issue. Or I need to filter the columns using normal django forms.
Here is my filter class filter.py
Pi_FILTER_CHOICES= (('', 'Select PI#'),(1,"PI1"),(2,"PI2"),(3,"PI3"),)
class PI_NameFilter(filters.FilterSet):
pi_name = filters.ChoiceFilter( label = "PI Name", choices=Pi_FILTER_CHOICES)
class Meta:
modle = SamplesLinkage
Here is the filter on my template
{% block filter %}
<form action="" method="get">
<label for="id_pi_name">Search by PI: </label>
{{ filter.form.pi_name }}
<button type="submit" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Go Find
</button>
</form>
{% endblock %}
+3
source to share
1 answer
You (or at least anyone who will still face this issue in the future) should manually render form fields using this documentation: https://docs.djangoproject.com/en/1.11/topics/forms/#rendering -fields-manually
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Email subject:</label>
{{ form.subject }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Your message:</label>
{{ form.message }}
</div>
<div class="fieldWrapper">
{{ form.sender.errors }}
<label for="{{ form.sender.id_for_label }}">Your email address:</label>
{{ form.sender }}
</div>
<div class="fieldWrapper">
{{ form.cc_myself.errors }}
<label for="{{ form.cc_myself.id_for_label }}">CC yourself?</label>
{{ form.cc_myself }}
</div>
0
source to share