Django Filter

18 views
Skip to first unread message

David Turner

unread,
Jun 17, 2016, 11:58:40 AM6/17/16
to Django users
I am using django-filter

I have create the the filter as follows:
filters.py
import django_filters
from .models import Job


class JobFilter(django_filters.FilterSet):
    class Meta:
        model = Job
        fields = ['practice_type']

And I have created the following view:
from .models import Job
from .filters import JobFilter


def jobs_list(request):
    filter = JobFilter(request.GET, queryset=Job.objects.all())
    return render(request, 'jobs/jobs_list.html', {'filter': filter})

job_list.html
And then a templater as follows:
{% block content %}
    <form action="" method="get">
        {{ filter.form.as_p }}
        <input type="submit" />
    </form>
    {% for job in filter %}
        {{ job.name }} <br />
    {% endfor %}
{% endblock %}

Everything is fine and the filter shows on the relevant page

However on pressing submit no results are returned.

I know this is probably something quite simple but I have been staring at this for so long now any help would be appreciated.

David Turner

unread,
Jun 17, 2016, 12:09:14 PM6/17/16
to django...@googlegroups.com
The issue is that one of the fields use choices. If I remove this everything is fine!

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/nLi_L_Pm7as/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c454499d-ddfe-48b8-be67-53a7535de0b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages