2014-01-22 07:43:33 +01:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
2009-04-03 21:52:14 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-13 23:34:56 +02:00
|
|
|
from django.db import models
|
2009-04-03 21:52:14 +02:00
|
|
|
|
2011-10-13 23:34:56 +02:00
|
|
|
__all__ = (
|
|
|
|
"Link",
|
|
|
|
"Place",
|
|
|
|
"Restaurant",
|
|
|
|
"Person",
|
|
|
|
"Address",
|
|
|
|
"CharLink",
|
|
|
|
"TextLink",
|
|
|
|
"OddRelation1",
|
|
|
|
"OddRelation2",
|
2013-02-02 02:10:16 +01:00
|
|
|
"Contact",
|
|
|
|
"Organization",
|
|
|
|
"Note",
|
|
|
|
"Company",
|
|
|
|
)
|
2010-02-10 20:21:52 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2009-04-03 21:52:14 +02:00
|
|
|
class Link(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2009-04-03 21:52:14 +02:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2009-04-03 21:52:14 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2017-07-22 00:21:13 +02:00
|
|
|
class LinkProxy(Link):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2009-04-03 21:52:14 +02:00
|
|
|
class Place(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2018-03-13 03:42:48 +01:00
|
|
|
links = GenericRelation(Link, related_query_name="places")
|
2017-07-22 00:21:13 +02:00
|
|
|
link_proxy = GenericRelation(LinkProxy)
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-22 19:39:48 +01:00
|
|
|
class Restaurant(Place):
|
2020-04-30 09:13:23 +02:00
|
|
|
pass
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2017-12-05 22:08:50 +01:00
|
|
|
class Cafe(Restaurant):
|
2020-04-30 09:13:23 +02:00
|
|
|
pass
|
2017-12-05 22:08:50 +01:00
|
|
|
|
|
|
|
|
2010-01-22 19:39:48 +01:00
|
|
|
class Address(models.Model):
|
|
|
|
street = models.CharField(max_length=80)
|
|
|
|
city = models.CharField(max_length=50)
|
|
|
|
state = models.CharField(max_length=2)
|
|
|
|
zipcode = models.CharField(max_length=5)
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2010-01-22 19:39:48 +01:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-22 19:39:48 +01:00
|
|
|
class Person(models.Model):
|
|
|
|
account = models.IntegerField(primary_key=True)
|
|
|
|
name = models.CharField(max_length=128)
|
2014-01-22 07:43:33 +01:00
|
|
|
addresses = GenericRelation(Address)
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-29 18:58:22 +01:00
|
|
|
class CharLink(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2010-01-29 18:58:22 +01:00
|
|
|
object_id = models.CharField(max_length=100)
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2023-04-18 10:19:06 +02:00
|
|
|
value = models.CharField(max_length=250)
|
2010-01-29 18:58:22 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-29 18:58:22 +01:00
|
|
|
class TextLink(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2010-01-29 18:58:22 +01:00
|
|
|
object_id = models.TextField()
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2023-04-18 10:19:06 +02:00
|
|
|
value = models.CharField(max_length=250)
|
2010-01-29 18:58:22 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-29 18:58:22 +01:00
|
|
|
class OddRelation1(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-01-22 07:43:33 +01:00
|
|
|
clinks = GenericRelation(CharLink)
|
2010-01-29 18:58:22 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-01-29 18:58:22 +01:00
|
|
|
class OddRelation2(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-01-22 07:43:33 +01:00
|
|
|
tlinks = GenericRelation(TextLink)
|
2010-01-29 18:58:22 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-02-10 20:21:52 +01:00
|
|
|
# models for test_q_object_or:
|
|
|
|
class Note(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2010-02-10 20:21:52 +01:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2010-02-10 20:21:52 +01:00
|
|
|
note = models.TextField()
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-02-10 20:21:52 +01:00
|
|
|
class Contact(models.Model):
|
2014-01-22 07:43:33 +01:00
|
|
|
notes = GenericRelation(Note)
|
2010-02-10 20:21:52 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-02-10 20:21:52 +01:00
|
|
|
class Organization(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
contacts = models.ManyToManyField(Contact, related_name="organizations")
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-02-02 02:10:16 +01:00
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-01-22 07:43:33 +01:00
|
|
|
links = GenericRelation(Link)
|
2013-02-02 02:10:16 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-02-06 03:35:10 +01:00
|
|
|
class Team(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
def __len__(self):
|
2022-04-21 09:59:09 +02:00
|
|
|
return 0
|
2013-02-06 03:35:10 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-02-06 03:35:10 +01:00
|
|
|
class Guild(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
2017-01-19 15:55:03 +01:00
|
|
|
def __bool__(self):
|
|
|
|
return False
|
2013-02-06 03:35:10 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-02-06 03:35:10 +01:00
|
|
|
class Tag(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(
|
|
|
|
ContentType, models.CASCADE, related_name="g_r_r_tags"
|
|
|
|
)
|
2013-02-06 03:35:10 +01:00
|
|
|
object_id = models.CharField(max_length=15)
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey()
|
2013-02-06 03:35:10 +01:00
|
|
|
label = models.CharField(max_length=15)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-02-06 03:35:10 +01:00
|
|
|
class Board(models.Model):
|
2020-11-04 03:28:09 +01:00
|
|
|
name = models.CharField(primary_key=True, max_length=25)
|
2013-05-20 16:40:34 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2014-01-22 07:43:33 +01:00
|
|
|
class SpecialGenericRelation(GenericRelation):
|
2013-11-12 20:35:52 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-01-21 14:13:44 +01:00
|
|
|
super().__init__(*args, **kwargs)
|
2013-11-12 20:35:52 +01:00
|
|
|
self.editable = True
|
|
|
|
self.save_form_data_calls = 0
|
|
|
|
|
|
|
|
def save_form_data(self, *args, **kwargs):
|
|
|
|
self.save_form_data_calls += 1
|
|
|
|
|
|
|
|
|
2013-05-20 16:40:34 +02:00
|
|
|
class HasLinks(models.Model):
|
2018-08-09 03:25:18 +02:00
|
|
|
links = SpecialGenericRelation(Link, related_query_name="targets")
|
2013-05-20 16:40:34 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-05-20 16:40:34 +02:00
|
|
|
class HasLinkThing(HasLinks):
|
|
|
|
pass
|
2013-06-05 23:29:44 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-06-05 23:29:44 +02:00
|
|
|
class A(models.Model):
|
2017-05-06 16:56:28 +02:00
|
|
|
flag = models.BooleanField(null=True)
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2013-06-05 23:29:44 +02:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 07:43:33 +01:00
|
|
|
content_object = GenericForeignKey("content_type", "object_id")
|
2013-06-05 23:29:44 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-06-05 23:29:44 +02:00
|
|
|
class B(models.Model):
|
2014-01-22 07:43:33 +01:00
|
|
|
a = GenericRelation(A)
|
2013-06-05 23:29:44 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("id",)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-06-05 23:29:44 +02:00
|
|
|
class C(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
b = models.ForeignKey(B, models.CASCADE)
|
2013-06-05 23:29:44 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("id",)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-06-05 23:29:44 +02:00
|
|
|
class D(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
b = models.ForeignKey(B, models.SET_NULL, null=True)
|
2013-06-05 23:29:44 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("id",)
|
2014-07-14 18:42:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Ticket #22998
|
|
|
|
|
2022-02-03 20:24:19 +01:00
|
|
|
|
2014-07-14 18:42:14 +02:00
|
|
|
class Node(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2014-07-14 18:42:14 +02:00
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content = GenericForeignKey("content_type", "object_id")
|
|
|
|
|
|
|
|
|
|
|
|
class Content(models.Model):
|
|
|
|
nodes = GenericRelation(Node)
|
2015-07-22 16:43:21 +02:00
|
|
|
related_obj = models.ForeignKey("Related", models.CASCADE)
|
2014-07-14 18:42:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Related(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def prevent_deletes(sender, instance, **kwargs):
|
2019-08-20 09:54:41 +02:00
|
|
|
raise models.ProtectedError("Not allowed to delete.", [instance])
|
2014-07-14 18:42:14 +02:00
|
|
|
|
2016-11-12 18:11:23 +01:00
|
|
|
|
2014-07-14 18:42:14 +02:00
|
|
|
models.signals.pre_delete.connect(prevent_deletes, sender=Node)
|