You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+29
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@
17
17
# sequencefield
18
18
simple model field taking it's value from a postgres sequence. This is an easy replacement for django autofield offering the following advantages:
19
19
- Sequence could be shared among multiple models (db tables), so you can now have unique id among multiple django models
20
+
- Possibility to generate alphanumeric id of the form "{PREFIX}_{ID}"
20
21
- Unique Id could also be combined with data from other field to build complex id. One example is given that combine unique id with date information to offer an efficient table indexing/clustering for faster data retrieval when filtering on date. (Particularly useful with BRIN index)
21
22
22
23
@@ -51,6 +52,7 @@ class IntSequenceModel(models.Model):
51
52
IntSequenceConstraint(
52
53
name="%(app_label)s_%(class)s_custseq",
53
54
sequence="int_custseq", #name of sequence to use
55
+
drop=False, #avoid deleting the sequence if shared among multiple tables
54
56
fields=["id"], #name of the field that should be populated by this sequence
55
57
start=100, #first value of the sequence
56
58
maxvalue=200#max value allowed for the sequence, will raise error if we go above, use None for the maximum allowed value of the db
@@ -59,6 +61,26 @@ class IntSequenceModel(models.Model):
59
61
60
62
```
61
63
64
+
### Simple AlphaNumeric Example
65
+
Just add an AlphaNumericSequenceField field(s) to your models like this.
66
+
You can provide a "format" argument to define how to convert the number to char. The syntax is the one used in postgres to_char function ([see here](https://www.postgresql.org/docs/current/functions-formatting.html))
0 commit comments