mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Added templates for IPAM objects; cleaned up admin
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import CustomField, CustomFieldValue, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction
|
||||
from .models import CustomField, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction
|
||||
|
||||
|
||||
class CustomFieldForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = CustomField
|
||||
exclude = []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CustomFieldForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# Organize the available ContentTypes
|
||||
queryset = self.fields['obj_type'].queryset.order_by('app_label', 'model')
|
||||
self.fields['obj_type'].choices = [(ct.pk, '{} > {}'.format(ct.app_label, ct.name)) for ct in queryset]
|
||||
|
||||
|
||||
class CustomFieldChoiceAdmin(admin.TabularInline):
|
||||
@@ -11,6 +26,7 @@ class CustomFieldChoiceAdmin(admin.TabularInline):
|
||||
class CustomFieldAdmin(admin.ModelAdmin):
|
||||
inlines = [CustomFieldChoiceAdmin]
|
||||
list_display = ['name', 'models', 'type', 'required', 'default', 'description']
|
||||
form = CustomFieldForm
|
||||
|
||||
def models(self, obj):
|
||||
return ', '.join([ct.name for ct in obj.obj_type.all()])
|
||||
|
||||
@@ -43,7 +43,7 @@ class CustomFieldForm(forms.ModelForm):
|
||||
field = forms.CharField(max_length=100, required=cf.required, initial=cf.default)
|
||||
|
||||
field.model = cf
|
||||
field.label = cf.label if cf.label else cf.name
|
||||
field.label = cf.label if cf.label else cf.name.capitalize()
|
||||
field.help_text = cf.description
|
||||
self.fields[field_name] = field
|
||||
self.custom_fields.append(field_name)
|
||||
|
||||
@@ -8,7 +8,6 @@ from django.template import Template, Context
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
|
||||
# NOTE: Any model added here MUST have a GenericRelation defined for CustomField
|
||||
CUSTOMFIELD_MODELS = (
|
||||
'site', 'rack', 'device', # DCIM
|
||||
'aggregate', 'prefix', 'ipaddress', 'vlan', 'vrf', # IPAM
|
||||
|
||||
Reference in New Issue
Block a user