1
1
# Django Sqids
2
+
2
3
[ ![ Github Actions] ( https://github.com/julianwachholz/django-sqids/workflows/test/badge.svg )] ( https://github.com/julianwachholz/django-sqids/actions )
3
4
[ ![ Python Version] ( https://img.shields.io/pypi/pyversions/django-sqids.svg )] ( https://pypi.org/project/django-sqids/ )
4
5
[ ![ PyPI Package] ( https://img.shields.io/pypi/v/django-sqids.svg )] ( https://pypi.org/project/django-sqids/ )
@@ -9,14 +10,15 @@ django-sqids is a simple and non-intrusive [sqids](https://sqids.org/) library f
9
10
The project was forked from [ django-hashids] ( https://github.com/ericls/django-hashids ) to provide the same functionality with the newer Sqids library.
10
11
11
12
# Features
13
+
12
14
- Proxy the internal model ` pk ` field without storing the value in the database.
13
15
- Allows lookups and filtering by sqid string.
14
16
- Can be used as sort key
15
17
- Allows specifying a min_length and alphabet globally
16
18
- Supports custom min_length, and alphabet per field
17
19
- Supports Django REST Framework Serializers
18
20
- Supports exact ID searches in Django Admin when field is specified in search_fields.
19
- - Supports common filtering lookups, such as __ iexact, __ contains, __ icontains, though matching is the same as __ exact.
21
+ - Supports common filtering lookups, such as ` __iexact ` , ` __contains ` , ` __icontains ` , though matching is the same as ` __exact ` .
20
22
- Supports other lookups: isnull, gt, gte, lt and lte.
21
23
22
24
# Install
@@ -25,7 +27,7 @@ The project was forked from [django-hashids](https://github.com/ericls/django-ha
25
27
pip install django-sqids
26
28
```
27
29
28
- ` django-sqids ` is tested with Django 1.11, 2.2, 3.0, 3.1, 3. 2, 4 .0 and python 3.6, 3.7, 3.8, 3.9, 3.10 .
30
+ ` django-sqids ` is tested with Django 3.2, 4. 2, 5 .0 and Python 3.8 - 3.12 .
29
31
30
32
# Usage
31
33
@@ -84,20 +86,32 @@ class YourDetailView(DetailView):
84
86
slug_field = ' sqid'
85
87
```
86
88
89
+ ## Using with Django Admin
90
+
91
+ Add the field to your ModelAdmin's ` search_fields ` to quickly find a record by its Sqid:
92
+
93
+ ``` python
94
+ class MyModelAdmin (admin .ModelAdmin ):
95
+ search_fields = [
96
+ " sqid__exact" ,
97
+ ]
98
+ ```
99
+
87
100
## Config
88
101
89
102
The folloing attributes can be added in settings file to set default arguments of ` SqidsField ` :
103
+
90
104
1 . ` DJANGO_SQIDS_MIN_LENGTH ` : default minimum length
91
105
2 . ` DJANGO_SQIDS_ALPHABET ` : default alphabet
92
106
93
107
` SqidsField ` does not reqiure any arguments but the following arguments can be supplied to modify its behavior.
94
108
95
- | Name | Description |
96
- | ------------------ | :-- -----------------------------------------------------: |
97
- | ` real_field_name ` | The proxied field name |
98
- | ` sqids_instance ` | The sqids instance used to encode/decode for this field |
99
- | ` min_length ` | The minimum length of sqids generated for this field |
100
- | ` alphabet ` | The alphabet used by this field to generate sqids |
109
+ | Name | Description |
110
+ | ----------------- | :-----------------------------------------------------: |
111
+ | ` real_field_name ` | The proxied field name |
112
+ | ` sqids_instance ` | The sqids instance used to encode/decode for this field |
113
+ | ` min_length ` | The minimum length of sqids generated for this field |
114
+ | ` alphabet ` | The alphabet used by this field to generate sqids |
101
115
102
116
The argument ` sqids_instance ` is mutually exclusive to ` min_length ` and ` alphabet ` . See [ sqids-python] ( https://github.com/sqids/sqids-python ) for more info about the arguments.
103
117
@@ -118,4 +132,4 @@ class MyModel(models.Model):
118
132
class HexModel (models .Model ):
119
133
sqid = SqidsField(alphabet = shuffle_alphabet(seed = ' randomSeed' , alphabet = ' 0123456789abcdef' ))
120
134
121
- ```
135
+ ```
0 commit comments