1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Jeremy Stretch 8dcbd66de6 Closes #13427: Public model registration (#14152)
* Initial work on #13427

* Clarify documentation

* Reference public models registry when populating models for ConfigTemplate context
2023-11-03 10:32:59 -04:00

61 lines
1.5 KiB
Python

import uuid
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import gettext_lazy as _
from utilities.fields import RestrictedGenericForeignKey
from ..fields import CachedValueField
__all__ = (
'CachedValue',
)
class CachedValue(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False
)
timestamp = models.DateTimeField(
verbose_name=_('timestamp'),
auto_now_add=True,
editable=False
)
object_type = models.ForeignKey(
to=ContentType,
on_delete=models.CASCADE,
related_name='+'
)
object_id = models.PositiveBigIntegerField()
object = RestrictedGenericForeignKey(
ct_field='object_type',
fk_field='object_id'
)
field = models.CharField(
verbose_name=_('field'),
max_length=200
)
type = models.CharField(
verbose_name=_('type'),
max_length=30
)
value = CachedValueField(
verbose_name=_('value'),
)
weight = models.PositiveSmallIntegerField(
verbose_name=_('weight'),
default=1000
)
_netbox_private = True
class Meta:
ordering = ('weight', 'object_type', 'value', 'object_id')
verbose_name = _('cached value')
verbose_name_plural = _('cached values')
def __str__(self):
return f'{self.object_type} {self.object_id}: {self.field}={self.value}'