# Path: hashid_field/field.py
# class HashidField(HashidFieldMixin, HashidCharFieldMixin, models.IntegerField):
#     description = "A Hashids obscured IntegerField"
# 
# class BigHashidField(HashidFieldMixin, HashidCharFieldMixin, models.BigIntegerField):
#     description = "A Hashids obscured BigIntegerField"
# 
#     def __init__(self, min_length=settings.HASHID_FIELD_BIG_MIN_LENGTH, *args, **kwargs):
#         super().__init__(min_length=min_length, *args, **kwargs)
# 
# class HashidAutoField(HashidFieldMixin, models.AutoField):
#     description = "A Hashids obscured AutoField"
# 
# class BigHashidAutoField(HashidFieldMixin, models.AutoField):
#     # This inherits from AutoField instead of BigAutoField so that DEFAULT_AUTO_FIELD doesn't throw an error
#     description = "A Hashids obscured BigAutoField"
# 
#     def get_internal_type(self):
#         return 'BigAutoField'
# 
#     def rel_db_type(self, connection):
#         return models.BigIntegerField().db_type(connection=connection)
# 
#     def __init__(self, min_length=settings.HASHID_FIELD_BIG_MIN_LENGTH, *args, **kwargs):
#         super().__init__(min_length=min_length, *args, **kwargs)


from django.db import models
from hashid_field import HashidAutoField, HashidField, BigHashidAutoField, BigHashidField
from django.urls import reverse




class Author(models.Model):
    id = BigHashidAutoField(primary_key=True, prefix="a_", alphabet="0123456789abcdef")
    name = models.CharField(max_length=40)
    uid = models.UUIDField(null=True, blank=True)
    id_str = models.CharField(max_length=15, blank=True)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.id_str = str(self.id)
        super().save(*args, **kwargs)


class Editor(models.Model):
    id = HashidAutoField(primary_key=True, salt="A different salt", min_length=20)
    name = models.CharField(max_length=40)

    def __str__(self):
        return self.name


class Book(models.Model):
    name = models.CharField(max_length=40)
    author = models.ForeignKey(Author, on_delete=models.CASCADE, null=True, blank=True, related_name='books')
    reference_id = HashidField(salt="alternative salt", allow_int_lookup=True, prefix="ref_")

# Path: hashid_field/field.py
# class HashidField(HashidFieldMixin, HashidCharFieldMixin, models.IntegerField):
#     description = "A Hashids obscured IntegerField"
# 
# class BigHashidField(HashidFieldMixin, HashidCharFieldMixin, models.BigIntegerField):
#     description = "A Hashids obscured BigIntegerField"
# 
#     def __init__(self, min_length=settings.HASHID_FIELD_BIG_MIN_LENGTH, *args, **kwargs):
#         super().__init__(min_length=min_length, *args, **kwargs)
# 
# class HashidAutoField(HashidFieldMixin, models.AutoField):
#     description = "A Hashids obscured AutoField"
# 
# class BigHashidAutoField(HashidFieldMixin, models.AutoField):
#     # This inherits from AutoField instead of BigAutoField so that DEFAULT_AUTO_FIELD doesn't throw an error
#     description = "A Hashids obscured BigAutoField"
# 
#     def get_internal_type(self):
#         return 'BigAutoField'
# 
#     def rel_db_type(self, connection):
#         return models.BigIntegerField().db_type(connection=connection)
# 
#     def __init__(self, min_length=settings.HASHID_FIELD_BIG_MIN_LENGTH, *args, **kwargs):
#         super().__init__(min_length=min_length, *args, **kwargs)


# Path: sandbox/library/models.py
from django.db import models
from hashid_field import HashidAutoField, HashidField, BigHashidAutoField, BigHashidField
from django.urls import reverse





class Author(models.Model):
    id = BigHashidAutoField(primary_key=True, prefix="a_", alphabet="0123456789abcdef")
    name = models.CharField(max_length=40)
    uid = models.UUIDField(null=True, blank=True)
    id_str = models.CharField(max_length=15, blank=True)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.id_str = str(self.id)
        super().save(*args, **kwargs)


class Editor(models.Model):
    id = HashidAutoField(primary_key=True, salt="A different salt", min_length=20)
    name = models.CharField(max_length=40)

    def __str__(self):
        return self.name


class Book(models.Model):
    name = models.CharField(max_length=40)
    author = models.ForeignKey(Author, on_delete=models.CASCADE, null=True, blank=True, related_name='books')
    reference_id = HashidField(salt="alternative salt", allow_int_lookup=True, prefix="ref_")

    key = HashidField(min_length=10, alphabet="abcdlmnotuvwxyz0123789", null=True, blank=True)