File: models.py

package info (click to toggle)
django-polymodels 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208 kB
  • sloc: python: 1,373; makefile: 6; sh: 5
file content (71 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from django.db import models

from polymodels.fields import PolymorphicTypeField
from polymodels.models import PolymorphicModel


class Zoo(models.Model):
    animals = models.ManyToManyField("Animal", related_name="zoos")


class Animal(PolymorphicModel):
    name = models.CharField(max_length=50)

    class Meta:
        ordering = ["id"]

    def __str__(self):
        return self.name


class NotInstalledAnimal(Animal):
    class Meta:
        app_label = "not_installed"


class Mammal(Animal):
    pass


class Monkey(Mammal):
    friends = models.ManyToManyField("self")


class Trait(PolymorphicModel):
    trait_type = PolymorphicTypeField(
        "self", on_delete=models.CASCADE, blank=True, null=True
    )
    mammal_type = PolymorphicTypeField(
        Mammal, on_delete=models.CASCADE, blank=True, null=True
    )
    snake_type = PolymorphicTypeField("Snake", on_delete=models.CASCADE)


class AcknowledgedTrait(Trait):
    class Meta:
        proxy = True


class Reptile(Animal):
    length = models.SmallIntegerField()

    class Meta:
        abstract = True
        ordering = ["id"]


class Snake(Reptile):
    color = models.CharField(max_length=100, blank=True)

    class Meta:
        ordering = ["id"]


class BigSnake(Snake):
    class Meta:
        proxy = True


class HugeSnake(BigSnake):
    class Meta:
        proxy = True