about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/pgvector/django/bit.py
diff options
context:
space:
mode:
Diffstat (limited to '.venv/lib/python3.12/site-packages/pgvector/django/bit.py')
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/django/bit.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/pgvector/django/bit.py b/.venv/lib/python3.12/site-packages/pgvector/django/bit.py
new file mode 100644
index 00000000..2cc847ad
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/django/bit.py
@@ -0,0 +1,32 @@
+from django import forms
+from django.db.models import Field
+
+
+# https://docs.djangoproject.com/en/5.0/howto/custom-model-fields/
+class BitField(Field):
+    description = 'Bit string'
+
+    def __init__(self, *args, length=None, **kwargs):
+        self.length = length
+        super().__init__(*args, **kwargs)
+
+    def deconstruct(self):
+        name, path, args, kwargs = super().deconstruct()
+        if self.length is not None:
+            kwargs['length'] = self.length
+        return name, path, args, kwargs
+
+    def db_type(self, connection):
+        if self.length is None:
+            return 'bit'
+        return 'bit(%d)' % self.length
+
+    def formfield(self, **kwargs):
+        return super().formfield(form_class=BitFormField, **kwargs)
+
+
+class BitFormField(forms.CharField):
+    def to_python(self, value):
+        if isinstance(value, str) and value == '':
+            return None
+        return super().to_python(value)