Kaydet (Commit) a6e7ebf4 authored tarafından Jon Dufresne's avatar Jon Dufresne Kaydeden (comit) Tim Graham

[2.1.x] Added test of filtering on BinaryField and corrected docs.

Backport of fb2964a4 from master.
üst f5335bc7
...@@ -416,9 +416,8 @@ guaranteed to fit numbers from ``-9223372036854775808`` to ...@@ -416,9 +416,8 @@ guaranteed to fit numbers from ``-9223372036854775808`` to
.. class:: BinaryField(max_length=None, **options) .. class:: BinaryField(max_length=None, **options)
A field to store raw binary data. It only supports ``bytes`` assignment. Be A field to store raw binary data. It can be assigned :class:`bytes` or a
aware that this field has limited functionality. For example, it is not possible :class:`memoryview`.
to filter a queryset on a ``BinaryField`` value.
By default, ``BinaryField`` sets :attr:`~Field.editable` to ``False``, in which By default, ``BinaryField`` sets :attr:`~Field.editable` to ``False``, in which
case it can't be included in a :class:`~django.forms.ModelForm`. case it can't be included in a :class:`~django.forms.ModelForm`.
......
...@@ -34,3 +34,13 @@ class BinaryFieldTests(TestCase): ...@@ -34,3 +34,13 @@ class BinaryFieldTests(TestCase):
self.assertIs(field.editable, True) self.assertIs(field.editable, True)
field = models.BinaryField(editable=False) field = models.BinaryField(editable=False)
self.assertIs(field.editable, False) self.assertIs(field.editable, False)
def test_filter(self):
dm = DataModel.objects.create(data=self.binary_data)
DataModel.objects.create(data=b'\xef\xbb\xbf')
self.assertSequenceEqual(DataModel.objects.filter(data=self.binary_data), [dm])
def test_filter_memoryview(self):
dm = DataModel.objects.create(data=self.binary_data)
DataModel.objects.create(data=b'\xef\xbb\xbf')
self.assertSequenceEqual(DataModel.objects.filter(data=memoryview(self.binary_data)), [dm])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment