File: models.py

package info (click to toggle)
python-django 3%3A6.0~beta1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,252 kB
  • sloc: python: 371,056; javascript: 19,376; xml: 211; makefile: 187; sh: 28
file content (28 lines) | stat: -rw-r--r-- 733 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
from django.db import models


class Person(models.Model):
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    friends = models.ManyToManyField("self")

    system_check_run_count = 0

    @classmethod
    def check(cls, *args, **kwargs):
        cls.system_check_run_count += 1
        return super().check(**kwargs)


# A set of models that use a non-abstract inherited 'through' model.
class ThroughBase(models.Model):
    person = models.ForeignKey(Person, models.CASCADE)
    b = models.ForeignKey("B", models.CASCADE)


class Through(ThroughBase):
    extra = models.CharField(max_length=20)


class B(models.Model):
    people = models.ManyToManyField(Person, through=Through)