2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.fields import NoneType, UnionField, SafeMapField
|
2019-06-10 21:24:35 +00:00
|
|
|
|
|
|
|
|
2020-06-01 08:29:50 +00:00
|
|
|
class ModelLabels(SafeMapField):
|
2019-06-10 21:24:35 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2020-06-01 08:29:50 +00:00
|
|
|
super(ModelLabels, self).__init__(
|
|
|
|
field=UnionField(types=(int, NoneType)), *args, **kwargs
|
|
|
|
)
|
2019-06-10 21:24:35 +00:00
|
|
|
|
|
|
|
def validate(self, value):
|
|
|
|
super(ModelLabels, self).validate(value)
|
2020-06-01 08:29:50 +00:00
|
|
|
non_empty_values = list(filter(None, value.values()))
|
|
|
|
if non_empty_values and len(set(non_empty_values)) < len(non_empty_values):
|
2019-06-10 21:24:35 +00:00
|
|
|
self.error("Same label id appears more than once in model labels")
|