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

Standardize model types based on function

This commit is contained in:
Jeremy Stretch
2021-02-24 21:01:16 -05:00
parent 0a6ebdee48
commit bec7ea7072
31 changed files with 1569 additions and 579 deletions

View File

@@ -0,0 +1,27 @@
import django.core.serializers.json
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tenancy', '0011_standardize_name_length'),
]
operations = [
migrations.AddField(
model_name='tenantgroup',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
),
migrations.AlterField(
model_name='tenant',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='tenantgroup',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
]

View File

@@ -3,11 +3,11 @@ from django.urls import reverse
from mptt.models import MPTTModel, TreeForeignKey
from taggit.managers import TaggableManager
from extras.models import ChangeLoggedModel, CustomFieldModel, ObjectChange, TaggedItem
from extras.models import ObjectChange, TaggedItem
from extras.utils import extras_features
from netbox.models import NestedGroupModel, PrimaryModel
from utilities.mptt import TreeManager
from utilities.querysets import RestrictedQuerySet
from utilities.utils import serialize_object
__all__ = (
@@ -16,7 +16,8 @@ __all__ = (
)
class TenantGroup(MPTTModel, ChangeLoggedModel):
@extras_features('custom_fields', 'export_templates', 'webhooks')
class TenantGroup(NestedGroupModel):
"""
An arbitrary collection of Tenants.
"""
@@ -48,12 +49,6 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
class Meta:
ordering = ['name']
class MPTTMeta:
order_insertion_by = ['name']
def __str__(self):
return self.name
def get_absolute_url(self):
return "{}?group={}".format(reverse('tenancy:tenant_list'), self.slug)
@@ -65,18 +60,9 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
self.description,
)
def to_objectchange(self, action):
# Remove MPTT-internal fields
return ObjectChange(
changed_object=self,
object_repr=str(self),
action=action,
object_data=serialize_object(self, exclude=['level', 'lft', 'rght', 'tree_id'])
)
@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
class Tenant(ChangeLoggedModel, CustomFieldModel):
class Tenant(PrimaryModel):
"""
A Tenant represents an organization served by the NetBox owner. This is typically a customer or an internal
department.