1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.db.models import Model
from hashids import Hashids
from django_hashids import HashidsField
class TestModel(Model):
hashid = HashidsField(real_field_name="id")
class TestModelWithDifferentConfig(Model):
hashid = HashidsField(salt="AAA", min_length=5, alphabet="OPQRST1234567890")
this_hashids_instance = Hashids(salt="FOO")
class TestModelWithOwnInstance(Model):
hashid = HashidsField(hashids_instance=this_hashids_instance)
class TestUser(AbstractUser):
hashid = HashidsField(real_field_name="id")
class TestUserRelated(Model):
hashid = HashidsField(real_field_name="id")
user = models.ForeignKey("TestUser", related_name="related", on_delete=models.CASCADE)
class FirstSubClass(TestModel):
pass
class SecondSubClass(FirstSubClass):
pass
class TestAbstractModel(models.Model):
hashid = HashidsField(real_field_name="id")
class Meta:
abstract = True
class ModelA(TestAbstractModel):
pass
class ModelB(ModelA):
pass
class ModelUsingPKAsRealFieldName(Model):
hashid = HashidsField(real_field_name="pk")
|