mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 18:38:38 -06:00
Add custom fields to tags.
This commit is contained in:
parent
47a6fc19ca
commit
6d9abb9d29
@ -8,6 +8,7 @@ from dcim.api.nested_serializers import (
|
|||||||
NestedRegionSerializer, NestedSiteSerializer,
|
NestedRegionSerializer, NestedSiteSerializer,
|
||||||
)
|
)
|
||||||
from dcim.models import Device, DeviceRole, Platform, Rack, Region, Site
|
from dcim.models import Device, DeviceRole, Platform, Rack, Region, Site
|
||||||
|
from extras.api.customfields import CustomFieldModelSerializer
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import (
|
from extras.models import (
|
||||||
ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, JobResult, Tag,
|
ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, JobResult, Tag,
|
||||||
@ -88,13 +89,16 @@ class ExportTemplateSerializer(ValidatedModelSerializer):
|
|||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
|
||||||
class TagSerializer(ValidatedModelSerializer):
|
class TagSerializer(CustomFieldModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:tag-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:tag-detail')
|
||||||
tagged_items = serializers.IntegerField(read_only=True)
|
tagged_items = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Tag
|
model = Tag
|
||||||
fields = ['id', 'url', 'name', 'slug', 'color', 'description', 'tagged_items']
|
fields = [
|
||||||
|
'id', 'url', 'name', 'slug', 'color', 'description', 'custom_fields',
|
||||||
|
'tagged_items',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class TaggedObjectSerializer(serializers.Serializer):
|
class TaggedObjectSerializer(serializers.Serializer):
|
||||||
|
@ -124,7 +124,7 @@ class ExportTemplateViewSet(ModelViewSet):
|
|||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
|
||||||
class TagViewSet(ModelViewSet):
|
class TagViewSet(CustomFieldModelViewSet):
|
||||||
queryset = Tag.objects.annotate(
|
queryset = Tag.objects.annotate(
|
||||||
tagged_items=Count('extras_taggeditem_items')
|
tagged_items=Count('extras_taggeditem_items')
|
||||||
).order_by(*Tag._meta.ordering)
|
).order_by(*Tag._meta.ordering)
|
||||||
|
@ -152,7 +152,7 @@ class CustomFieldFilterForm(forms.Form):
|
|||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
|
||||||
class TagForm(BootstrapMixin, forms.ModelForm):
|
class TagForm(BootstrapMixin, CustomFieldModelForm):
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from taggit.models import TagBase, GenericTaggedItemBase
|
from taggit.models import TagBase, GenericTaggedItemBase
|
||||||
|
|
||||||
from extras.models import ChangeLoggedModel
|
from extras.models import ChangeLoggedModel, CustomFieldModel
|
||||||
|
from extras.utils import extras_features
|
||||||
from utilities.choices import ColorChoices
|
from utilities.choices import ColorChoices
|
||||||
from utilities.fields import ColorField
|
from utilities.fields import ColorField
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
@ -12,7 +14,8 @@ from utilities.querysets import RestrictedQuerySet
|
|||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
|
||||||
class Tag(TagBase, ChangeLoggedModel):
|
@extras_features('custom_fields')
|
||||||
|
class Tag(TagBase, ChangeLoggedModel, CustomFieldModel):
|
||||||
color = ColorField(
|
color = ColorField(
|
||||||
default=ColorChoices.COLOR_GREY
|
default=ColorChoices.COLOR_GREY
|
||||||
)
|
)
|
||||||
@ -20,6 +23,11 @@ class Tag(TagBase, ChangeLoggedModel):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
custom_field_values = GenericRelation(
|
||||||
|
to='extras.CustomFieldValue',
|
||||||
|
content_type_field='obj_type',
|
||||||
|
object_id_field='obj_id'
|
||||||
|
)
|
||||||
|
|
||||||
objects = RestrictedQuerySet.as_manager()
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
|
||||||
|
@ -11,4 +11,12 @@
|
|||||||
{% render_field form.description %}
|
{% render_field form.description %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if form.custom_fields %}
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading"><strong>Custom Fields</strong></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
{% render_custom_fields form %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user