File: models.py

package info (click to toggle)
strawberry-graphql-django 0.78.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,624 kB
  • sloc: python: 31,895; makefile: 24; sh: 21
file content (44 lines) | stat: -rw-r--r-- 1,340 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
import django
from django.db import models


class Company(models.Model):
    name = models.CharField(max_length=100)
    main_project = models.ForeignKey(
        "Project", null=True, blank=True, on_delete=models.CASCADE
    )

    class Meta:
        ordering = ("name",)


class Project(models.Model):
    company = models.ForeignKey(
        Company,
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        related_name="projects",
    )
    topic = models.CharField(max_length=30)
    artist = models.CharField(max_length=30, blank=True)
    supervisor = models.CharField(max_length=30, blank=True)
    research_notes = models.TextField(blank=True)

    class Meta:
        constraints = (
            models.CheckConstraint(
                **(
                    {  # type: ignore[arg-type]
                        "condition": (models.Q(artist="") | models.Q(supervisor=""))
                        & (~models.Q(topic="") | ~models.Q(topic=""))
                    }
                    if django.VERSION >= (5, 1)
                    else {
                        "check": (models.Q(artist="") | models.Q(supervisor=""))
                        & (~models.Q(topic="") | ~models.Q(topic=""))
                    }
                ),
                name="artist_xor_supervisor",
            ),
        )