Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
"""
|
|
|
|
Various complex queries that have been problematic in the past.
|
|
|
|
"""
|
2022-09-21 22:17:04 +00:00
|
|
|
import datetime
|
|
|
|
|
2010-10-19 04:07:22 +00:00
|
|
|
from django.db import models
|
2019-07-24 06:42:41 +00:00
|
|
|
from django.db.models.functions import Now
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2009-03-24 03:59:38 +00:00
|
|
|
class DumbCategory(models.Model):
|
|
|
|
pass
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-05-09 17:33:31 +00:00
|
|
|
class ProxyCategory(DumbCategory):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2009-03-24 03:59:38 +00:00
|
|
|
class NamedCategory(DumbCategory):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-09-06 22:13:51 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
"self",
|
|
|
|
models.SET_NULL,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
related_name="children",
|
2022-02-03 19:24:19 +00:00
|
|
|
)
|
2015-07-22 14:43:21 +00:00
|
|
|
category = models.ForeignKey(
|
|
|
|
NamedCategory, models.SET_NULL, null=True, default=None
|
|
|
|
)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2008-08-15 03:36:18 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Note(models.Model):
|
|
|
|
note = models.CharField(max_length=100)
|
2020-10-27 05:39:52 +00:00
|
|
|
misc = models.CharField(max_length=25)
|
2015-08-20 16:46:14 +00:00
|
|
|
tag = models.ForeignKey(Tag, models.SET_NULL, blank=True, null=True)
|
2020-07-28 11:56:39 +00:00
|
|
|
negate = models.BooleanField(default=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["note"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.note
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-29 03:01:46 +00:00
|
|
|
class Annotation(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
tag = models.ForeignKey(Tag, models.CASCADE)
|
2008-06-29 03:01:46 +00:00
|
|
|
notes = models.ManyToManyField(Note)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-06-29 03:01:46 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2019-06-24 15:48:10 +00:00
|
|
|
class DateTimePK(models.Model):
|
2022-09-21 22:17:04 +00:00
|
|
|
date = models.DateTimeField(primary_key=True, default=datetime.datetime.now)
|
2019-06-24 15:48:10 +00:00
|
|
|
|
2022-09-17 15:44:37 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ["date"]
|
|
|
|
|
2019-06-24 15:48:10 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class ExtraInfo(models.Model):
|
|
|
|
info = models.CharField(max_length=100)
|
2017-04-22 21:04:02 +00:00
|
|
|
note = models.ForeignKey(Note, models.CASCADE, null=True)
|
2013-02-20 19:09:27 +00:00
|
|
|
value = models.IntegerField(null=True)
|
2019-06-24 15:48:10 +00:00
|
|
|
date = models.ForeignKey(DateTimePK, models.SET_NULL, null=True)
|
2020-06-05 19:01:39 +00:00
|
|
|
filterable = models.BooleanField(default=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["info"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.info
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
num = models.IntegerField(unique=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
extra = models.ForeignKey(ExtraInfo, models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2009-08-20 16:05:25 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
created = models.DateTimeField()
|
2008-06-25 13:38:06 +00:00
|
|
|
modified = models.DateTimeField(blank=True, null=True)
|
2014-07-08 20:42:40 +00:00
|
|
|
tags = models.ManyToManyField(Tag, blank=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
creator = models.ForeignKey(Author, models.CASCADE)
|
|
|
|
note = models.ForeignKey(Note, models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["-note", "name"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Report(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
creator = models.ForeignKey(Author, models.SET_NULL, to_field="num", null=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2017-04-22 21:04:02 +00:00
|
|
|
class ReportComment(models.Model):
|
|
|
|
report = models.ForeignKey(Report, models.CASCADE)
|
|
|
|
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Ranking(models.Model):
|
|
|
|
rank = models.IntegerField()
|
2015-07-22 14:43:21 +00:00
|
|
|
author = models.ForeignKey(Author, models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
# A complex ordering specification. Should stress the system a bit.
|
|
|
|
ordering = ("author__extra__note", "author__name", "rank")
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return "%d: %s" % (self.rank, self.author.name)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Cover(models.Model):
|
|
|
|
title = models.CharField(max_length=50)
|
2015-07-22 14:43:21 +00:00
|
|
|
item = models.ForeignKey(Item, models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["item"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
return self.title
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Number(models.Model):
|
|
|
|
num = models.IntegerField()
|
2019-07-09 21:26:37 +00:00
|
|
|
other_num = models.IntegerField(null=True)
|
2020-06-27 21:41:32 +00:00
|
|
|
another_num = models.IntegerField(null=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2016-12-29 15:27:49 +00:00
|
|
|
return str(self.num)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2014-03-02 14:25:53 +00:00
|
|
|
# Symmetrical m2m field with a normal field using the reverse accessor name
|
2008-06-26 10:50:25 +00:00
|
|
|
# ("valid").
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-06-26 10:50:25 +00:00
|
|
|
class Valid(models.Model):
|
|
|
|
valid = models.CharField(max_length=10)
|
|
|
|
parent = models.ManyToManyField("self")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["valid"]
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-06-26 10:50:25 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
# Some funky cross-linked models for testing a couple of infinite recursion
|
|
|
|
# cases.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class X(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
y = models.ForeignKey("Y", models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class Y(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
x1 = models.ForeignKey(X, models.CASCADE, related_name="y1")
|
2022-02-03 19:24:19 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
# Some models with a cycle in the default ordering. This would be bad if we
|
|
|
|
# didn't catch the infinite loop.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class LoopX(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
y = models.ForeignKey("LoopY", models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["y"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class LoopY(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
x = models.ForeignKey(LoopX, models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["x"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
class LoopZ(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
z = models.ForeignKey("self", models.CASCADE)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["z"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-04-28 11:51:16 +00:00
|
|
|
# A model and custom default manager combination.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-04-28 11:51:16 +00:00
|
|
|
class CustomManager(models.Manager):
|
2013-03-08 14:15:23 +00:00
|
|
|
def get_queryset(self):
|
2017-01-21 13:13:44 +00:00
|
|
|
qs = super().get_queryset()
|
2008-06-26 03:11:32 +00:00
|
|
|
return qs.filter(public=True, tag__name="t1")
|
2008-04-28 11:51:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-04-28 11:51:16 +00:00
|
|
|
class ManagedModel(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
tag = models.ForeignKey(Tag, models.CASCADE)
|
2008-06-26 03:11:32 +00:00
|
|
|
public = models.BooleanField(default=True)
|
2008-04-28 11:51:16 +00:00
|
|
|
|
|
|
|
objects = CustomManager()
|
|
|
|
normal_manager = models.Manager()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-04-28 11:51:16 +00:00
|
|
|
return self.data
|
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-06-26 01:02:11 +00:00
|
|
|
# An inter-related setup with multiple paths from Child to Detail.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-06-26 01:02:11 +00:00
|
|
|
class Detail(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-26 01:02:11 +00:00
|
|
|
class MemberManager(models.Manager):
|
2013-03-08 14:15:23 +00:00
|
|
|
def get_queryset(self):
|
2017-01-21 13:13:44 +00:00
|
|
|
return super().get_queryset().select_related("details")
|
2008-06-26 01:02:11 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-26 01:02:11 +00:00
|
|
|
class Member(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
details = models.OneToOneField(Detail, models.CASCADE, primary_key=True)
|
2008-06-26 01:02:11 +00:00
|
|
|
|
|
|
|
objects = MemberManager()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-26 01:02:11 +00:00
|
|
|
class Child(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
person = models.OneToOneField(Member, models.CASCADE, primary_key=True)
|
|
|
|
parent = models.ForeignKey(Member, models.CASCADE, related_name="children")
|
2008-06-26 01:02:11 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-06-29 11:15:48 +00:00
|
|
|
# Custom primary keys interfered with ordering in the past.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-06-29 11:15:48 +00:00
|
|
|
class CustomPk(models.Model):
|
|
|
|
name = models.CharField(max_length=10, primary_key=True)
|
|
|
|
extra = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name", "extra"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-29 11:15:48 +00:00
|
|
|
class Related(models.Model):
|
2016-08-17 20:09:50 +00:00
|
|
|
custom = models.ForeignKey(CustomPk, models.CASCADE, null=True)
|
2008-06-29 11:15:48 +00:00
|
|
|
|
2014-01-28 19:36:57 +00:00
|
|
|
|
|
|
|
class CustomPkTag(models.Model):
|
|
|
|
id = models.CharField(max_length=20, primary_key=True)
|
|
|
|
custom_pk = models.ManyToManyField(CustomPk)
|
|
|
|
tag = models.CharField(max_length=20)
|
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-07-27 04:18:52 +00:00
|
|
|
# An inter-related setup with a model subclass that has a nullable
|
|
|
|
# path to another model, and a return path from that model.
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-07-27 04:18:52 +00:00
|
|
|
class Celebrity(models.Model):
|
|
|
|
name = models.CharField("Name", max_length=20)
|
2015-07-22 14:43:21 +00:00
|
|
|
greatest_fan = models.ForeignKey("Fan", models.SET_NULL, null=True, unique=True)
|
2008-07-27 04:18:52 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-12-22 20:42:40 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-07-27 04:18:52 +00:00
|
|
|
class TvChef(Celebrity):
|
|
|
|
pass
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-07-27 04:18:52 +00:00
|
|
|
class Fan(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
fan_of = models.ForeignKey(Celebrity, models.CASCADE)
|
2008-07-27 04:18:52 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-07-27 18:16:17 +00:00
|
|
|
# Multiple foreign keys
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-07-27 18:16:17 +00:00
|
|
|
class LeafA(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-07-27 18:16:17 +00:00
|
|
|
return self.data
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-07-27 18:16:17 +00:00
|
|
|
class LeafB(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-07-27 18:16:17 +00:00
|
|
|
class Join(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
a = models.ForeignKey(LeafA, models.CASCADE)
|
|
|
|
b = models.ForeignKey(LeafB, models.CASCADE)
|
2008-04-28 11:51:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-09-01 12:07:26 +00:00
|
|
|
class ReservedName(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
order = models.IntegerField()
|
2008-09-02 02:16:41 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-09-01 12:07:26 +00:00
|
|
|
return self.name
|
2008-09-02 02:16:41 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2008-12-07 05:48:01 +00:00
|
|
|
# A simpler shared-foreign-key setup that can expose some problems.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-12-07 05:48:01 +00:00
|
|
|
class SharedConnection(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-08-20 08:33:44 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.data
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-12-07 05:48:01 +00:00
|
|
|
class PointerA(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
connection = models.ForeignKey(SharedConnection, models.CASCADE)
|
2008-12-07 05:48:01 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-12-07 05:48:01 +00:00
|
|
|
class PointerB(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
connection = models.ForeignKey(SharedConnection, models.CASCADE)
|
2008-12-07 05:48:01 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2009-02-28 02:59:40 +00:00
|
|
|
# Multi-layer ordering
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2009-02-28 02:59:40 +00:00
|
|
|
class SingleObject(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-02-28 02:59:40 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2009-02-28 02:59:40 +00:00
|
|
|
class RelatedObject(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
single = models.ForeignKey(SingleObject, models.SET_NULL, null=True)
|
2012-08-25 13:33:07 +00:00
|
|
|
f = models.IntegerField(null=True)
|
2009-02-28 02:59:40 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["single"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2009-02-28 02:59:40 +00:00
|
|
|
class Plaything(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 14:43:21 +00:00
|
|
|
others = models.ForeignKey(RelatedObject, models.SET_NULL, null=True)
|
2009-02-28 02:59:40 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["others"]
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-02-28 02:59:40 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-10-19 04:07:22 +00:00
|
|
|
class Article(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
created = models.DateTimeField()
|
2011-01-25 03:14:28 +00:00
|
|
|
|
2014-05-16 09:55:09 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-01-25 03:14:28 +00:00
|
|
|
class Food(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-01-25 03:14:28 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-01-25 03:14:28 +00:00
|
|
|
class Eaten(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
food = models.ForeignKey(Food, models.SET_NULL, to_field="name", null=True)
|
2011-01-25 03:14:28 +00:00
|
|
|
meal = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s at %s" % (self.food, self.meal)
|
2011-01-25 03:14:28 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-01-25 03:14:28 +00:00
|
|
|
class Node(models.Model):
|
|
|
|
num = models.IntegerField(unique=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey("self", models.SET_NULL, to_field="num", null=True)
|
2011-01-25 03:14:28 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2020-05-01 14:54:15 +00:00
|
|
|
return str(self.num)
|
2011-03-03 13:51:54 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2011-03-03 13:51:54 +00:00
|
|
|
# Bug #12252
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2011-03-03 13:51:54 +00:00
|
|
|
class ObjectA(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-03-03 13:51:54 +00:00
|
|
|
return self.name
|
|
|
|
|
2014-10-28 01:36:47 +00:00
|
|
|
def __iter__(self):
|
|
|
|
# Ticket #23721
|
|
|
|
assert False, "type checking should happen without calling model __iter__"
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2014-06-14 07:24:19 +00:00
|
|
|
class ProxyObjectA(ObjectA):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
|
|
|
class ChildObjectA(ObjectA):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2011-03-03 13:51:54 +00:00
|
|
|
class ObjectB(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 14:43:21 +00:00
|
|
|
objecta = models.ForeignKey(ObjectA, models.CASCADE)
|
2020-10-27 05:39:52 +00:00
|
|
|
num = models.PositiveIntegerField()
|
2011-03-03 13:51:54 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-03-03 13:51:54 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2014-06-14 07:24:19 +00:00
|
|
|
class ProxyObjectB(ObjectB):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2011-03-03 13:51:54 +00:00
|
|
|
class ObjectC(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 14:43:21 +00:00
|
|
|
objecta = models.ForeignKey(ObjectA, models.SET_NULL, null=True)
|
|
|
|
objectb = models.ForeignKey(ObjectB, models.SET_NULL, null=True)
|
|
|
|
childobjecta = models.ForeignKey(
|
|
|
|
ChildObjectA, models.SET_NULL, null=True, related_name="ca_pk"
|
|
|
|
)
|
2011-03-03 13:51:54 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2013-09-03 18:22:21 +00:00
|
|
|
return self.name
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-08-23 03:38:42 +00:00
|
|
|
class SimpleCategory(models.Model):
|
2020-10-27 05:39:52 +00:00
|
|
|
name = models.CharField(max_length=25)
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-08-23 03:38:42 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-08-23 03:38:42 +00:00
|
|
|
class SpecialCategory(SimpleCategory):
|
2020-10-27 05:39:52 +00:00
|
|
|
special_name = models.CharField(max_length=35)
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-08-23 03:38:42 +00:00
|
|
|
return self.name + " " + self.special_name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-08-23 03:38:42 +00:00
|
|
|
class CategoryItem(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
category = models.ForeignKey(SimpleCategory, models.CASCADE)
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-09-30 10:28:39 +00:00
|
|
|
return "category item: " + str(self.category)
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2018-01-20 19:48:01 +00:00
|
|
|
class MixedCaseFieldCategoryItem(models.Model):
|
|
|
|
CaTeGoRy = models.ForeignKey(SimpleCategory, models.CASCADE)
|
|
|
|
|
|
|
|
|
|
|
|
class MixedCaseDbColumnCategoryItem(models.Model):
|
|
|
|
category = models.ForeignKey(
|
|
|
|
SimpleCategory, models.CASCADE, db_column="CaTeGoRy_Id"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2011-08-23 03:38:42 +00:00
|
|
|
class OneToOneCategory(models.Model):
|
2011-08-23 06:28:45 +00:00
|
|
|
new_name = models.CharField(max_length=15)
|
2015-07-22 14:43:21 +00:00
|
|
|
category = models.OneToOneField(SimpleCategory, models.CASCADE)
|
2011-08-23 03:38:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-08-23 03:38:42 +00:00
|
|
|
return "one2one " + self.new_name
|
2012-04-29 10:45:46 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-09-29 17:02:25 +00:00
|
|
|
class CategoryRelationship(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
first = models.ForeignKey(SimpleCategory, models.CASCADE, related_name="first_rel")
|
|
|
|
second = models.ForeignKey(
|
|
|
|
SimpleCategory, models.CASCADE, related_name="second_rel"
|
|
|
|
)
|
2013-09-29 17:02:25 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2018-01-20 19:48:01 +00:00
|
|
|
class CommonMixedCaseForeignKeys(models.Model):
|
|
|
|
category = models.ForeignKey(CategoryItem, models.CASCADE)
|
|
|
|
mixed_case_field_category = models.ForeignKey(
|
|
|
|
MixedCaseFieldCategoryItem, models.CASCADE
|
|
|
|
)
|
|
|
|
mixed_case_db_column_category = models.ForeignKey(
|
|
|
|
MixedCaseDbColumnCategoryItem, models.CASCADE
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-04-29 10:45:46 +00:00
|
|
|
class NullableName(models.Model):
|
|
|
|
name = models.CharField(max_length=20, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["id"]
|
2012-08-21 15:43:08 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-21 15:43:08 +00:00
|
|
|
class ModelD(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-21 15:43:08 +00:00
|
|
|
class ModelC(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-21 15:43:08 +00:00
|
|
|
class ModelB(models.Model):
|
|
|
|
name = models.TextField()
|
2015-07-22 14:43:21 +00:00
|
|
|
c = models.ForeignKey(ModelC, models.CASCADE)
|
2012-08-21 15:43:08 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-21 15:43:08 +00:00
|
|
|
class ModelA(models.Model):
|
|
|
|
name = models.TextField()
|
2015-07-22 14:43:21 +00:00
|
|
|
b = models.ForeignKey(ModelB, models.SET_NULL, null=True)
|
|
|
|
d = models.ForeignKey(ModelD, models.CASCADE)
|
2012-08-25 13:33:07 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 13:33:07 +00:00
|
|
|
class Job(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 13:33:07 +00:00
|
|
|
class JobResponsibilities(models.Model):
|
2016-03-18 14:24:29 +00:00
|
|
|
job = models.ForeignKey(Job, models.CASCADE, to_field="name")
|
|
|
|
responsibility = models.ForeignKey(
|
|
|
|
"Responsibility", models.CASCADE, to_field="description"
|
|
|
|
)
|
2012-08-25 13:33:07 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 13:33:07 +00:00
|
|
|
class Responsibility(models.Model):
|
|
|
|
description = models.CharField(max_length=20, unique=True)
|
|
|
|
jobs = models.ManyToManyField(
|
|
|
|
Job, through=JobResponsibilities, related_name="responsibilities"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.description
|
2012-08-25 11:13:37 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2012-08-25 11:13:37 +00:00
|
|
|
# Models for disjunction join promotion low level testing.
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2012-08-25 11:13:37 +00:00
|
|
|
class FK1(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 11:13:37 +00:00
|
|
|
class FK2(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 11:13:37 +00:00
|
|
|
class FK3(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-08-25 11:13:37 +00:00
|
|
|
class BaseA(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
a = models.ForeignKey(FK1, models.SET_NULL, null=True)
|
|
|
|
b = models.ForeignKey(FK2, models.SET_NULL, null=True)
|
|
|
|
c = models.ForeignKey(FK3, models.SET_NULL, null=True)
|
2013-02-17 23:56:24 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-17 23:56:24 +00:00
|
|
|
class Identifier(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-17 23:56:24 +00:00
|
|
|
class Program(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
identifier = models.OneToOneField(Identifier, models.CASCADE)
|
2013-02-17 23:56:24 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-17 23:56:24 +00:00
|
|
|
class Channel(models.Model):
|
|
|
|
programs = models.ManyToManyField(Program)
|
2015-07-22 14:43:21 +00:00
|
|
|
identifier = models.OneToOneField(Identifier, models.CASCADE)
|
2013-02-28 13:04:12 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-28 13:04:12 +00:00
|
|
|
class Book(models.Model):
|
|
|
|
title = models.TextField()
|
2015-07-22 14:43:21 +00:00
|
|
|
chapter = models.ForeignKey("Chapter", models.CASCADE)
|
2013-02-28 13:04:12 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-28 13:04:12 +00:00
|
|
|
class Chapter(models.Model):
|
|
|
|
title = models.TextField()
|
2015-07-22 14:43:21 +00:00
|
|
|
paragraph = models.ForeignKey("Paragraph", models.CASCADE)
|
2013-02-28 13:04:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Paragraph(models.Model):
|
|
|
|
text = models.TextField()
|
|
|
|
page = models.ManyToManyField("Page")
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-02-28 13:04:12 +00:00
|
|
|
class Page(models.Model):
|
|
|
|
text = models.TextField()
|
2013-03-01 23:06:56 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-03-01 23:06:56 +00:00
|
|
|
class MyObject(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
"self", models.SET_NULL, null=True, blank=True, related_name="children"
|
|
|
|
)
|
2013-03-01 23:06:56 +00:00
|
|
|
data = models.CharField(max_length=100)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
# Models for #17600 regressions
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
class Order(models.Model):
|
|
|
|
id = models.IntegerField(primary_key=True)
|
2018-11-22 03:58:43 +00:00
|
|
|
name = models.CharField(max_length=12, null=True, default="")
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
2017-12-28 20:07:29 +00:00
|
|
|
ordering = ("pk",)
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-01 14:54:15 +00:00
|
|
|
return str(self.pk)
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
class OrderItem(models.Model):
|
2016-03-18 14:24:29 +00:00
|
|
|
order = models.ForeignKey(Order, models.CASCADE, related_name="items")
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
status = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
2017-12-28 20:07:29 +00:00
|
|
|
ordering = ("pk",)
|
Refactored qs.add_q() and utils/tree.py
The sql/query.py add_q method did a lot of where/having tree hacking to
get complex queries to work correctly. The logic was refactored so that
it should be simpler to understand. The new logic should also produce
leaner WHERE conditions.
The changes cascade somewhat, as some other parts of Django (like
add_filter() and WhereNode) expect boolean trees in certain format or
they fail to work. So to fix the add_q() one must fix utils/tree.py,
some things in add_filter(), WhereNode and so on.
This commit also fixed add_filter to see negate clauses up the path.
A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to
.filter(~Q(reversefk__in=a_list)). The reason for this is that only
the immediate parent negate clauses were seen by add_filter, and thus a
tree like AND: (NOT AND: (AND: condition)) will not be handled
correctly, as there is one intermediary AND node in the tree. The
example tree is generated by .exclude(~Q(reversefk__in=a_list)).
Still, aggregation lost connectors in OR cases, and F() objects and
aggregates in same filter clause caused GROUP BY problems on some
databases.
Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2012-05-24 21:27:24 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-01 14:54:15 +00:00
|
|
|
return str(self.pk)
|
2013-08-22 07:42:10 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-08-22 07:42:10 +00:00
|
|
|
class BaseUser(models.Model):
|
2021-11-30 13:50:13 +00:00
|
|
|
annotation = models.ForeignKey(Annotation, models.CASCADE, null=True, blank=True)
|
2013-08-22 07:42:10 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-08-22 07:42:10 +00:00
|
|
|
class Task(models.Model):
|
|
|
|
title = models.CharField(max_length=10)
|
2016-03-18 14:24:29 +00:00
|
|
|
owner = models.ForeignKey(BaseUser, models.CASCADE, related_name="owner")
|
|
|
|
creator = models.ForeignKey(BaseUser, models.CASCADE, related_name="creator")
|
2021-11-30 13:50:13 +00:00
|
|
|
note = models.ForeignKey(Note, on_delete=models.CASCADE, null=True, blank=True)
|
2013-08-22 07:42:10 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-08-22 07:42:10 +00:00
|
|
|
class Staff(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-08-22 07:42:10 +00:00
|
|
|
class StaffUser(BaseUser):
|
2016-03-18 14:24:29 +00:00
|
|
|
staff = models.OneToOneField(Staff, models.CASCADE, related_name="user")
|
2013-08-22 07:42:10 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2021-10-02 17:49:02 +00:00
|
|
|
return str(self.staff)
|
2013-10-01 08:07:41 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-10-01 08:07:41 +00:00
|
|
|
class Ticket21203Parent(models.Model):
|
|
|
|
parentid = models.AutoField(primary_key=True)
|
|
|
|
parent_bool = models.BooleanField(default=True)
|
|
|
|
created = models.DateTimeField(auto_now=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-10-01 08:07:41 +00:00
|
|
|
class Ticket21203Child(models.Model):
|
|
|
|
childid = models.AutoField(primary_key=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey(Ticket21203Parent, models.CASCADE)
|
2013-11-02 20:35:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
|
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
employees = models.ManyToManyField(
|
|
|
|
Person, related_name="employers", through="Employment"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Employment(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
employer = models.ForeignKey(Company, models.CASCADE)
|
|
|
|
employee = models.ForeignKey(Person, models.CASCADE)
|
2013-11-02 20:35:45 +00:00
|
|
|
title = models.CharField(max_length=128)
|
2014-04-28 12:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class School(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Student(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
school = models.ForeignKey(School, models.CASCADE)
|
2014-04-28 12:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Classroom(models.Model):
|
2016-10-26 22:01:37 +00:00
|
|
|
name = models.CharField(max_length=20)
|
2017-05-06 14:56:28 +00:00
|
|
|
has_blackboard = models.BooleanField(null=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
school = models.ForeignKey(School, models.CASCADE)
|
2014-04-28 12:27:36 +00:00
|
|
|
students = models.ManyToManyField(Student, related_name="classroom")
|
2014-10-07 13:07:46 +00:00
|
|
|
|
|
|
|
|
2017-03-02 14:36:25 +00:00
|
|
|
class Teacher(models.Model):
|
|
|
|
schools = models.ManyToManyField(School)
|
|
|
|
friends = models.ManyToManyField("self")
|
|
|
|
|
|
|
|
|
2015-07-13 07:54:39 +00:00
|
|
|
class Ticket23605AParent(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605A(Ticket23605AParent):
|
2014-10-07 13:07:46 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605B(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
modela_fk = models.ForeignKey(Ticket23605A, models.CASCADE)
|
|
|
|
modelc_fk = models.ForeignKey("Ticket23605C", models.CASCADE)
|
2014-10-07 13:07:46 +00:00
|
|
|
field_b0 = models.IntegerField(null=True)
|
|
|
|
field_b1 = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605C(models.Model):
|
|
|
|
field_c0 = models.FloatField()
|
2015-04-16 05:39:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
# db_table names have capital letters to ensure they are quoted in queries.
|
|
|
|
class Individual(models.Model):
|
|
|
|
alive = models.BooleanField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "Individual"
|
|
|
|
|
|
|
|
|
|
|
|
class RelatedIndividual(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
related = models.ForeignKey(
|
|
|
|
Individual, models.CASCADE, related_name="related_individual"
|
|
|
|
)
|
2015-04-16 05:39:31 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "RelatedIndividual"
|
2018-09-18 20:14:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CustomDbColumn(models.Model):
|
|
|
|
custom_column = models.IntegerField(db_column="custom_name", null=True)
|
|
|
|
ip_address = models.GenericIPAddressField(null=True)
|
2019-07-24 06:42:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreatedField(models.DateTimeField):
|
|
|
|
db_returning = True
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
kwargs.setdefault("default", Now)
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class ReturningModel(models.Model):
|
|
|
|
created = CreatedField(editable=False)
|
|
|
|
|
|
|
|
|
|
|
|
class NonIntegerPKReturningModel(models.Model):
|
|
|
|
created = CreatedField(editable=False, primary_key=True)
|
2019-06-09 00:56:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class JSONFieldNullable(models.Model):
|
|
|
|
json_field = models.JSONField(blank=True, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {"supports_json_field"}
|