def to_internal_value(self, data): try: value = super(HashidSerializerMixin, self).to_internal_value(data) return Hashid(value, salt=self.hashid_salt, min_length=self.hashid_min_length, alphabet=self.hashid_alphabet) except ValueError: raise serializers.ValidationError("Invalid int or Hashid string")
def to_internal_value(self, data): try: value = super().to_internal_value(data) if isinstance( value, str ) and self.hashid_prefix is not None and value.startswith( self.hashid_prefix): value = value[len(self.hashid_prefix) + 1:] return Hashid(value, hashids=self._hashids, hashids_cpp=self._hashids_cpp) except ValueError: raise serializers.ValidationError("Invalid id format.")
def no_cache(): from hashid_field.hashid import Hashid instances = [Hashid(i, salt="asdf", min_length=7) for i in range(1, 10_000)] return instances
def to_internal_value(self, data): try: value = super().to_internal_value(data) return Hashid(value, hashids=self._hashids) except ValueError: raise serializers.ValidationError("Invalid int or Hashid string")
def with_cache(): from hashid_field.hashid import Hashid from hashids import Hashids hashids = Hashids(salt="asdf", min_length=7) instances = [Hashid(i, hashids=hashids) for i in range(1, 10_000)] return instances