Source code for nested_admin.tests.one_deep.models

from __future__ import unicode_literals

from django.db import models
from django.db.models import ForeignKey, CASCADE
from nested_admin.tests.compat import python_2_unicode_compatible


[docs]@python_2_unicode_compatible class RootAbstract(models.Model): slug = models.CharField(max_length=128)
[docs] class Meta: abstract = True
def __str__(self): return self.slug
[docs]@python_2_unicode_compatible class ChildAbstract(models.Model): slug = models.CharField(max_length=128, help_text="Halp") position = models.PositiveIntegerField() boolean = models.BooleanField(default=False) readonly = models.CharField(max_length=255) text = models.TextField(default='')
[docs] class Meta: abstract = True
def __str__(self): parts = ["%s[%d]" % (self.slug, self.position)] if self.root: parts.insert(0, "%s" % self.root) return "/".join(parts)
[docs]class PlainStackedRoot(RootAbstract): class Meta: verbose_name = "Stacked Root" verbose_name_plural = "Stacked Roots"
[docs]class PlainStackedChild(ChildAbstract): root = ForeignKey(PlainStackedRoot, related_name='children', on_delete=CASCADE) class Meta: ordering = ('root', 'position') verbose_name = "Stacked Child" verbose_name_plural = "Stacked Children"
[docs]class PlainTabularRoot(RootAbstract): class Meta: verbose_name = "Tabular Root" verbose_name_plural = "Tabular Roots"
[docs]class PlainTabularChild(ChildAbstract): root = ForeignKey(PlainTabularRoot, related_name='children', on_delete=CASCADE) class Meta: ordering = ('root', 'position') verbose_name = "Tabular Child" verbose_name_plural = "Tabular Children"
[docs]class NestedStackedRoot(RootAbstract): class Meta: verbose_name = "Stacked Root" verbose_name_plural = "Stacked Roots"
[docs]class NestedStackedChild(ChildAbstract): root = ForeignKey(NestedStackedRoot, related_name='children', on_delete=CASCADE) class Meta: ordering = ('root', 'position') verbose_name = "Stacked Child" verbose_name_plural = "Stacked Children"
[docs]class NestedTabularRoot(RootAbstract): class Meta: verbose_name = "Tabular Root" verbose_name_plural = "Tabular Roots"
[docs]class NestedTabularChild(ChildAbstract): root = ForeignKey(NestedTabularRoot, related_name='children', on_delete=CASCADE) class Meta: ordering = ('root', 'position') verbose_name = "Tabular Child" verbose_name_plural = "Tabular Children"