Oleg Komarov
dfaaccee4a
this field is really a CharField with appropriate validation: it is always presented and processed as a string previous implementation was rather inefficient and VersionStringField.from_db_value was showing up in API profiling: validation was happening every time a Version object was initialized by ORM migrations have to be changed retroactively to remove parameters that become invalid, but this doesn't affect the data
17 lines
441 B
Python
17 lines
441 B
Python
from django.core.exceptions import ValidationError
|
|
from django.db.models import CharField
|
|
from semantic_version import Version
|
|
|
|
|
|
def validate_version_string(version_string):
|
|
try:
|
|
Version.parse(version_string)
|
|
except ValueError as e:
|
|
raise ValidationError(e)
|
|
|
|
|
|
class VersionStringField(CharField):
|
|
description = "A field to store serializable semantic versions"
|
|
|
|
default_validators = [validate_version_string]
|