mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Initial work on #13427 * Clarify documentation * Reference public models registry when populating models for ConfigTemplate context
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from .contenttypes import *
|
||||
from .data import *
|
||||
from .files import *
|
||||
from .jobs import *
|
||||
|
32
netbox/core/models/contenttypes.py
Normal file
32
netbox/core/models/contenttypes.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.contrib.contenttypes.models import ContentType as ContentType_, ContentTypeManager as ContentTypeManager_
|
||||
from django.db.models import Q
|
||||
|
||||
from netbox.registry import registry
|
||||
|
||||
__all__ = (
|
||||
'ContentType',
|
||||
'ContentTypeManager',
|
||||
)
|
||||
|
||||
|
||||
class ContentTypeManager(ContentTypeManager_):
|
||||
|
||||
def public(self):
|
||||
"""
|
||||
Filter the base queryset to return only ContentTypes corresponding to "public" models; those which are listed
|
||||
in registry['models'] and intended for reference by other objects.
|
||||
"""
|
||||
q = Q()
|
||||
for app_label, models in registry['models'].items():
|
||||
q |= Q(app_label=app_label, model__in=models)
|
||||
return self.get_queryset().filter(q)
|
||||
|
||||
|
||||
class ContentType(ContentType_):
|
||||
"""
|
||||
Wrap Django's native ContentType model to use our custom manager.
|
||||
"""
|
||||
objects = ContentTypeManager()
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
@@ -378,6 +378,8 @@ class AutoSyncRecord(models.Model):
|
||||
fk_field='object_id'
|
||||
)
|
||||
|
||||
_netbox_private = True
|
||||
|
||||
class Meta:
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
|
@@ -44,6 +44,7 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
||||
)
|
||||
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
_netbox_private = True
|
||||
|
||||
class Meta:
|
||||
ordering = ('file_root', 'file_path')
|
||||
|
Reference in New Issue
Block a user