| Server IP : 68.178.202.69 / Your IP : 216.73.216.143 Web Server : Apache System : Linux 69.202.178.68.host.secureserver.net 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64 User : ikioworld ( 1005) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/opt/nydus/ops/shortuuid/ |
Upload File : |
from typing import Any
from typing import Dict
from typing import Tuple
from django.db import models
from django.utils.translation import gettext_lazy as _
from . import ShortUUID
class ShortUUIDField(models.CharField):
description = _("A short UUID field.")
def __init__(self, *args: Any, **kwargs: Any) -> None:
self.length: int = kwargs.pop("length", 22) # type: ignore
self.prefix: str = kwargs.pop("prefix", "") # type: ignore
if "max_length" not in kwargs:
# If `max_length` was not specified, set it here.
kwargs["max_length"] = self.length + len(self.prefix) # type: ignore
self.alphabet: str = kwargs.pop("alphabet", None) # type: ignore
kwargs["default"] = self._generate_uuid # type: ignore
super().__init__(*args, **kwargs)
def _generate_uuid(self) -> str:
"""Generate a short random string."""
return self.prefix + ShortUUID(alphabet=self.alphabet).random(
length=self.length
)
def deconstruct(self) -> Tuple[str, str, Tuple, Dict[str, Any]]:
name, path, args, kwargs = super().deconstruct()
kwargs["alphabet"] = self.alphabet
kwargs["length"] = self.length
kwargs["prefix"] = self.prefix
kwargs.pop("default", None)
return name, path, args, kwargs