Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default value of filterset data to MultiValueDict #1634

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db import models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields.related import ManyToManyRel, ManyToOneRel, OneToOneRel
from django.utils.datastructures import MultiValueDict

from .conf import settings
from .constants import ALL_FIELDS
Expand Down Expand Up @@ -176,7 +177,7 @@ def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
model = queryset.model

self.is_bound = data is not None
self.data = data or {}
self.data = data or MultiValueDict()
self.queryset = queryset
self.request = request
self.form_prefix = prefix
Expand Down
5 changes: 5 additions & 0 deletions tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.db import models
from django.test import TestCase, override_settings
from django.utils.datastructures import MultiValueDict

from django_filters.exceptions import FieldLookupError
from django_filters.filters import (
Expand Down Expand Up @@ -745,6 +746,10 @@ def test_creating_with_request(self):
m = mock.Mock()
f = self.F(request=m)
self.assertEqual(f.request, m)

def test_creating_with_no_data_default(self):
f = self.F()
self.assertIsInstance(f.data, MultiValueDict)


class FilterSetQuerysetTests(TestCase):
Expand Down