from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from philo.exceptions import AncestorDoesNotExist
from philo.models.fields import JSONField
from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter
from philo.exceptions import AncestorDoesNotExist
from philo.models.fields import JSONField
from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter
def value_formfield(self, **kwargs):
kwargs['initial'] = self.value_json
def value_formfield(self, **kwargs):
kwargs['initial'] = self.value_json
value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True)
value = generic.GenericForeignKey('value_content_type', 'value_object_id')
value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True)
value = generic.GenericForeignKey('value_content_type', 'value_object_id')
slug = models.SlugField(max_length=255)
def get_path(self, root=None, pathsep='/', field='slug'):
slug = models.SlugField(max_length=255)
def get_path(self, root=None, pathsep='/', field='slug'):
if root is not None and not self.is_descendant_of(root):
raise AncestorDoesNotExist(root)
qs = self.get_ancestors()
if root is not None:
if root is not None and not self.is_descendant_of(root):
raise AncestorDoesNotExist(root)
qs = self.get_ancestors()
if root is not None:
return pathsep.join([getattr(parent, field, '?') for parent in list(qs) + [self]])
path = property(get_path)
return pathsep.join([getattr(parent, field, '?') for parent in list(qs) + [self]])
path = property(get_path)