Skip to content

Commit 3b74f07

Browse files
Update README
1 parent 8d1a8ac commit 3b74f07

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Django Sqids
2+
23
[![Github Actions](https://github.com/julianwachholz/django-sqids/workflows/test/badge.svg)](https://github.com/julianwachholz/django-sqids/actions)
34
[![Python Version](https://img.shields.io/pypi/pyversions/django-sqids.svg)](https://pypi.org/project/django-sqids/)
45
[![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
910
The project was forked from [django-hashids](https://github.com/ericls/django-hashids) to provide the same functionality with the newer Sqids library.
1011

1112
# Features
13+
1214
- Proxy the internal model `pk` field without storing the value in the database.
1315
- Allows lookups and filtering by sqid string.
1416
- Can be used as sort key
1517
- Allows specifying a min_length and alphabet globally
1618
- Supports custom min_length, and alphabet per field
1719
- Supports Django REST Framework Serializers
1820
- 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`.
2022
- Supports other lookups: isnull, gt, gte, lt and lte.
2123

2224
# Install
@@ -25,7 +27,7 @@ The project was forked from [django-hashids](https://github.com/ericls/django-ha
2527
pip install django-sqids
2628
```
2729

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.
2931

3032
# Usage
3133

@@ -84,20 +86,32 @@ class YourDetailView(DetailView):
8486
slug_field = 'sqid'
8587
```
8688

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+
87100
## Config
88101

89102
The folloing attributes can be added in settings file to set default arguments of `SqidsField`:
103+
90104
1. `DJANGO_SQIDS_MIN_LENGTH`: default minimum length
91105
2. `DJANGO_SQIDS_ALPHABET`: default alphabet
92106

93107
`SqidsField` does not reqiure any arguments but the following arguments can be supplied to modify its behavior.
94108

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 |
101115

102116
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.
103117

@@ -118,4 +132,4 @@ class MyModel(models.Model):
118132
class HexModel(models.Model):
119133
sqid = SqidsField(alphabet=shuffle_alphabet(seed='randomSeed', alphabet='0123456789abcdef'))
120134

121-
```
135+
```

0 commit comments

Comments
 (0)