1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#8054: Support configurable status choices

This commit is contained in:
jeremystretch
2021-12-16 09:36:15 -05:00
parent 28f577738a
commit 419f86a4a5
7 changed files with 80 additions and 20 deletions

View File

@@ -1,7 +1,21 @@
from django.conf import settings
class ChoiceSetMeta(type):
"""
Metaclass for ChoiceSet
"""
def __new__(mcs, name, bases, attrs):
# Extend static choices with any configured choices
if 'key' in attrs:
try:
attrs['CHOICES'].extend(settings.FIELD_CHOICES[attrs['key']])
except KeyError:
pass
return super().__new__(mcs, name, bases, attrs)
def __call__(cls, *args, **kwargs):
# Django will check if a 'choices' value is callable, and if so assume that it returns an iterable
return getattr(cls, 'CHOICES', ())