mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-24 20:39:59 -06:00
Introduce AdminModel base class to provide enhanced UI functionality for Owner
This commit is contained in:
@@ -11,10 +11,9 @@ from netbox.models.features import *
|
|||||||
from netbox.models.mixins import OwnerMixin
|
from netbox.models.mixins import OwnerMixin
|
||||||
from utilities.mptt import TreeManager
|
from utilities.mptt import TreeManager
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
from utilities.views import get_viewname
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
'AdminModel',
|
||||||
'ChangeLoggedModel',
|
'ChangeLoggedModel',
|
||||||
'NestedGroupModel',
|
'NestedGroupModel',
|
||||||
'NetBoxModel',
|
'NetBoxModel',
|
||||||
@@ -44,6 +43,7 @@ class NetBoxFeatureSet(
|
|||||||
return f'{settings.STATIC_URL}docs/models/{self._meta.app_label}/{self._meta.model_name}/'
|
return f'{settings.STATIC_URL}docs/models/{self._meta.app_label}/{self._meta.model_name}/'
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
|
from utilities.views import get_viewname
|
||||||
return reverse(get_viewname(self), args=[self.pk])
|
return reverse(get_viewname(self), args=[self.pk])
|
||||||
|
|
||||||
|
|
||||||
@@ -222,3 +222,26 @@ class OrganizationalModel(OwnerMixin, NetBoxModel):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class AdminModel(
|
||||||
|
BookmarksMixin,
|
||||||
|
CloningMixin,
|
||||||
|
CustomLinksMixin,
|
||||||
|
CustomValidationMixin,
|
||||||
|
EventRulesMixin,
|
||||||
|
ExportTemplatesMixin,
|
||||||
|
NotificationsMixin,
|
||||||
|
BaseModel,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
A model which represents an administrative resource.
|
||||||
|
"""
|
||||||
|
description = models.CharField(
|
||||||
|
verbose_name=_('description'),
|
||||||
|
max_length=200,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from netbox.models import AdminModel
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -9,17 +10,12 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Owner(models.Model):
|
class Owner(AdminModel):
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
verbose_name=_('name'),
|
verbose_name=_('name'),
|
||||||
max_length=150,
|
max_length=150,
|
||||||
unique=True,
|
unique=True,
|
||||||
)
|
)
|
||||||
description = models.CharField(
|
|
||||||
verbose_name=_('description'),
|
|
||||||
max_length=200,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
groups = models.ManyToManyField(
|
groups = models.ManyToManyField(
|
||||||
to='users.Group',
|
to='users.Group',
|
||||||
verbose_name=_('groups'),
|
verbose_name=_('groups'),
|
||||||
@@ -36,6 +32,7 @@ class Owner(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
objects = RestrictedQuerySet.as_manager()
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
clone_fields = ('groups', 'users')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from urllib.parse import urlencode
|
|||||||
|
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
from netbox.models import CloningMixin
|
from netbox.models.features import CloningMixin
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'dict_to_querydict',
|
'dict_to_querydict',
|
||||||
|
|||||||
Reference in New Issue
Block a user