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

Use ContentTypeChoiceField for all ContentType fields

This commit is contained in:
Jeremy Stretch
2021-04-02 10:55:16 -04:00
parent 73e9842877
commit d82f2e289a
6 changed files with 45 additions and 48 deletions

View File

@ -21,6 +21,7 @@ from .utils import expand_alphanumeric_pattern, expand_ipaddress_pattern
__all__ = (
'CommentField',
'ContentTypeChoiceField',
'ContentTypeMultipleChoiceField',
'CSVChoiceField',
'CSVContentTypeField',
'CSVDataField',
@ -114,7 +115,7 @@ class JSONField(_JSONField):
return json.dumps(value, sort_keys=True, indent=4)
class ContentTypeChoiceField(forms.ModelChoiceField):
class ContentTypeChoiceMixin:
def __init__(self, queryset, *args, **kwargs):
# Order ContentTypes by app_label
@ -126,6 +127,14 @@ class ContentTypeChoiceField(forms.ModelChoiceField):
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
class ContentTypeChoiceField(ContentTypeChoiceMixin, forms.ModelChoiceField):
pass
class ContentTypeMultipleChoiceField(ContentTypeChoiceMixin, forms.ModelMultipleChoiceField):
pass
#
# CSV fields
#