mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
Split tenancy models into separate modules
This commit is contained in:
parent
c06b3374ce
commit
a3e7cab935
2
netbox/tenancy/models/__init__.py
Normal file
2
netbox/tenancy/models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from .contacts import *
|
||||||
|
from .tenants import *
|
@ -1,116 +1,22 @@
|
|||||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from mptt.models import MPTTModel, TreeForeignKey
|
from mptt.models import TreeForeignKey
|
||||||
|
|
||||||
from extras.utils import extras_features
|
from extras.utils import extras_features
|
||||||
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
||||||
|
from tenancy.choices import *
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
from .choices import *
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ContactAssignment',
|
'ContactAssignment',
|
||||||
'Contact',
|
'Contact',
|
||||||
'ContactGroup',
|
'ContactGroup',
|
||||||
'ContactRole',
|
'ContactRole',
|
||||||
'Tenant',
|
|
||||||
'TenantGroup',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Tenants
|
|
||||||
#
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
|
||||||
class TenantGroup(NestedGroupModel):
|
|
||||||
"""
|
|
||||||
An arbitrary collection of Tenants.
|
|
||||||
"""
|
|
||||||
name = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
slug = models.SlugField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
parent = TreeForeignKey(
|
|
||||||
to='self',
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name='children',
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
db_index=True
|
|
||||||
)
|
|
||||||
description = models.CharField(
|
|
||||||
max_length=200,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['name']
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('tenancy:tenantgroup', args=[self.pk])
|
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
|
||||||
class Tenant(PrimaryModel):
|
|
||||||
"""
|
|
||||||
A Tenant represents an organization served by the NetBox owner. This is typically a customer or an internal
|
|
||||||
department.
|
|
||||||
"""
|
|
||||||
name = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
slug = models.SlugField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
group = models.ForeignKey(
|
|
||||||
to='tenancy.TenantGroup',
|
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='tenants',
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
description = models.CharField(
|
|
||||||
max_length=200,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
comments = models.TextField(
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generic relations
|
|
||||||
contacts = GenericRelation(
|
|
||||||
to='tenancy.ContactAssignment'
|
|
||||||
)
|
|
||||||
|
|
||||||
objects = RestrictedQuerySet.as_manager()
|
|
||||||
|
|
||||||
clone_fields = [
|
|
||||||
'group', 'description',
|
|
||||||
]
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['name']
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('tenancy:tenant', args=[self.pk])
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Contacts
|
|
||||||
#
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
class ContactGroup(NestedGroupModel):
|
class ContactGroup(NestedGroupModel):
|
||||||
"""
|
"""
|
96
netbox/tenancy/models/tenants.py
Normal file
96
netbox/tenancy/models/tenants.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
|
from mptt.models import TreeForeignKey
|
||||||
|
|
||||||
|
from extras.utils import extras_features
|
||||||
|
from netbox.models import NestedGroupModel, PrimaryModel
|
||||||
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'Tenant',
|
||||||
|
'TenantGroup',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
class TenantGroup(NestedGroupModel):
|
||||||
|
"""
|
||||||
|
An arbitrary collection of Tenants.
|
||||||
|
"""
|
||||||
|
name = models.CharField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
slug = models.SlugField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
parent = TreeForeignKey(
|
||||||
|
to='self',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='children',
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
db_index=True
|
||||||
|
)
|
||||||
|
description = models.CharField(
|
||||||
|
max_length=200,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['name']
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('tenancy:tenantgroup', args=[self.pk])
|
||||||
|
|
||||||
|
|
||||||
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
class Tenant(PrimaryModel):
|
||||||
|
"""
|
||||||
|
A Tenant represents an organization served by the NetBox owner. This is typically a customer or an internal
|
||||||
|
department.
|
||||||
|
"""
|
||||||
|
name = models.CharField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
slug = models.SlugField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
group = models.ForeignKey(
|
||||||
|
to='tenancy.TenantGroup',
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
related_name='tenants',
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
description = models.CharField(
|
||||||
|
max_length=200,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
comments = models.TextField(
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generic relations
|
||||||
|
contacts = GenericRelation(
|
||||||
|
to='tenancy.ContactAssignment'
|
||||||
|
)
|
||||||
|
|
||||||
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
|
||||||
|
clone_fields = [
|
||||||
|
'group', 'description',
|
||||||
|
]
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['name']
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('tenancy:tenant', args=[self.pk])
|
Loading…
Reference in New Issue
Block a user