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 10:50:16 +08:00
|
|
|
"""
|
|
|
|
Various complex queries that have been problematic in the past.
|
|
|
|
"""
|
2010-03-27 23:16:27 +08:00
|
|
|
import threading
|
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 10:50:16 +08:00
|
|
|
|
2010-10-19 12:07:22 +08:00
|
|
|
from django.db import models
|
2019-07-24 14:42:41 +08: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 10:50:16 +08:00
|
|
|
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class DumbCategory(models.Model):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-05-10 01:33:31 +08:00
|
|
|
class ProxyCategory(DumbCategory):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class NamedCategory(DumbCategory):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-09-07 06:13:51 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
'self',
|
|
|
|
models.SET_NULL,
|
|
|
|
blank=True, null=True,
|
|
|
|
related_name='children',
|
|
|
|
)
|
|
|
|
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 10:50:16 +08:00
|
|
|
|
2008-08-15 11:36:18 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Note(models.Model):
|
|
|
|
note = models.CharField(max_length=100)
|
|
|
|
misc = models.CharField(max_length=10)
|
2015-08-21 00:46:14 +08:00
|
|
|
tag = models.ForeignKey(Tag, models.SET_NULL, blank=True, 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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['note']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.note
|
|
|
|
|
2010-03-27 23:16:27 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(*args, **kwargs)
|
2010-03-27 23:16:27 +08:00
|
|
|
# Regression for #13227 -- having an attribute that
|
2015-12-03 07:55:50 +08:00
|
|
|
# is unpicklable doesn't stop you from cloning queries
|
2010-03-27 23:16:27 +08:00
|
|
|
# that use objects of that type as an argument.
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-29 11:01:46 +08:00
|
|
|
class Annotation(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
tag = models.ForeignKey(Tag, models.CASCADE)
|
2008-06-29 11:01:46 +08:00
|
|
|
notes = models.ManyToManyField(Note)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-06-29 11:01:46 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2019-06-24 23:48:10 +08:00
|
|
|
class DateTimePK(models.Model):
|
|
|
|
date = models.DateTimeField(primary_key=True, auto_now_add=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 10:50:16 +08:00
|
|
|
class ExtraInfo(models.Model):
|
|
|
|
info = models.CharField(max_length=100)
|
2017-04-23 05:04:02 +08:00
|
|
|
note = models.ForeignKey(Note, models.CASCADE, null=True)
|
2013-02-21 03:09:27 +08:00
|
|
|
value = models.IntegerField(null=True)
|
2019-06-24 23:48:10 +08:00
|
|
|
date = models.ForeignKey(DateTimePK, models.SET_NULL, 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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['info']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.info
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
num = models.IntegerField(unique=True)
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
2009-08-21 00:05:25 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
created = models.DateTimeField()
|
2008-06-25 21:38:06 +08:00
|
|
|
modified = models.DateTimeField(blank=True, null=True)
|
2014-07-09 04:42:40 +08:00
|
|
|
tags = models.ManyToManyField(Tag, blank=True)
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['-note', 'name']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Report(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2017-04-23 05:04:02 +08: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 10:50:16 +08:00
|
|
|
class Ranking(models.Model):
|
|
|
|
rank = models.IntegerField()
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
# A complex ordering specification. Should stress the system a bit.
|
|
|
|
ordering = ('author__extra__note', 'author__name', 'rank')
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return '%d: %s' % (self.rank, self.author.name)
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Cover(models.Model):
|
|
|
|
title = models.CharField(max_length=50)
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['item']
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
return self.title
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Number(models.Model):
|
|
|
|
num = models.IntegerField()
|
2019-07-10 05:26:37 +08:00
|
|
|
other_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 10:50:16 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2016-12-29 23:27:49 +08: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 10:50:16 +08:00
|
|
|
|
2014-03-02 22:25:53 +08:00
|
|
|
# Symmetrical m2m field with a normal field using the reverse accessor name
|
2008-06-26 18:50:25 +08:00
|
|
|
# ("valid").
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-06-26 18:50:25 +08:00
|
|
|
class Valid(models.Model):
|
|
|
|
valid = models.CharField(max_length=10)
|
|
|
|
parent = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['valid']
|
|
|
|
|
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 10:50:16 +08:00
|
|
|
# Some funky cross-linked models for testing a couple of infinite recursion
|
|
|
|
# cases.
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class X(models.Model):
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class Y(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
x1 = models.ForeignKey(X, models.CASCADE, related_name='y1')
|
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 10:50:16 +08:00
|
|
|
|
|
|
|
# Some models with a cycle in the default ordering. This would be bad if we
|
|
|
|
# didn't catch the infinite loop.
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class LoopX(models.Model):
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['y']
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class LoopY(models.Model):
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['x']
|
|
|
|
|
2013-11-03 05:34:05 +08: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 10:50:16 +08:00
|
|
|
class LoopZ(models.Model):
|
2015-07-22 22:43:21 +08: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 10:50:16 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['z']
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-04-28 19:51:16 +08:00
|
|
|
# A model and custom default manager combination.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-04-28 19:51:16 +08:00
|
|
|
class CustomManager(models.Manager):
|
2013-03-08 22:15:23 +08:00
|
|
|
def get_queryset(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
qs = super().get_queryset()
|
2008-06-26 11:11:32 +08:00
|
|
|
return qs.filter(public=True, tag__name='t1')
|
2008-04-28 19:51:16 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-04-28 19:51:16 +08:00
|
|
|
class ManagedModel(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
tag = models.ForeignKey(Tag, models.CASCADE)
|
2008-06-26 11:11:32 +08:00
|
|
|
public = models.BooleanField(default=True)
|
2008-04-28 19:51:16 +08:00
|
|
|
|
|
|
|
objects = CustomManager()
|
|
|
|
normal_manager = models.Manager()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-04-28 19:51:16 +08:00
|
|
|
return self.data
|
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
# An inter-related setup with multiple paths from Child to Detail.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
class Detail(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
class MemberManager(models.Manager):
|
2013-03-08 22:15:23 +08:00
|
|
|
def get_queryset(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
return super().get_queryset().select_related("details")
|
2008-06-26 09:02:11 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
class Member(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
details = models.OneToOneField(Detail, models.CASCADE, primary_key=True)
|
2008-06-26 09:02:11 +08:00
|
|
|
|
|
|
|
objects = MemberManager()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
class Child(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
person = models.OneToOneField(Member, models.CASCADE, primary_key=True)
|
|
|
|
parent = models.ForeignKey(Member, models.CASCADE, related_name="children")
|
2008-06-26 09:02:11 +08:00
|
|
|
|
2008-06-29 19:15:48 +08:00
|
|
|
# Custom primary keys interfered with ordering in the past.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-06-29 19:15:48 +08: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-03 05:34:05 +08:00
|
|
|
|
2008-06-29 19:15:48 +08:00
|
|
|
class Related(models.Model):
|
2016-08-18 04:09:50 +08:00
|
|
|
custom = models.ForeignKey(CustomPk, models.CASCADE, null=True)
|
2008-06-29 19:15:48 +08:00
|
|
|
|
2014-01-29 03:36:57 +08: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)
|
|
|
|
|
2008-07-27 12:18:52 +08: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-03 05:34:05 +08:00
|
|
|
|
2008-07-27 12:18:52 +08:00
|
|
|
class Celebrity(models.Model):
|
|
|
|
name = models.CharField("Name", max_length=20)
|
2015-07-22 22:43:21 +08:00
|
|
|
greatest_fan = models.ForeignKey("Fan", models.SET_NULL, null=True, unique=True)
|
2008-07-27 12:18:52 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-23 04:42:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-07-27 12:18:52 +08:00
|
|
|
class TvChef(Celebrity):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-07-27 12:18:52 +08:00
|
|
|
class Fan(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
fan_of = models.ForeignKey(Celebrity, models.CASCADE)
|
2008-07-27 12:18:52 +08:00
|
|
|
|
2008-07-28 02:16:17 +08:00
|
|
|
# Multiple foreign keys
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-07-28 02:16:17 +08:00
|
|
|
class LeafA(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-07-28 02:16:17 +08:00
|
|
|
return self.data
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-07-28 02:16:17 +08:00
|
|
|
class LeafB(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-07-28 02:16:17 +08:00
|
|
|
class Join(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
a = models.ForeignKey(LeafA, models.CASCADE)
|
|
|
|
b = models.ForeignKey(LeafB, models.CASCADE)
|
2008-04-28 19:51:16 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-09-01 20:07:26 +08:00
|
|
|
class ReservedName(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
order = models.IntegerField()
|
2008-09-02 10:16:41 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-09-01 20:07:26 +08:00
|
|
|
return self.name
|
2008-09-02 10:16:41 +08:00
|
|
|
|
2008-12-07 13:48:01 +08:00
|
|
|
# A simpler shared-foreign-key setup that can expose some problems.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-12-07 13:48:01 +08:00
|
|
|
class SharedConnection(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2013-08-20 16:33:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.data
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-12-07 13:48:01 +08:00
|
|
|
class PointerA(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
connection = models.ForeignKey(SharedConnection, models.CASCADE)
|
2008-12-07 13:48:01 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-12-07 13:48:01 +08:00
|
|
|
class PointerB(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
connection = models.ForeignKey(SharedConnection, models.CASCADE)
|
2008-12-07 13:48:01 +08:00
|
|
|
|
2009-02-28 10:59:40 +08:00
|
|
|
# Multi-layer ordering
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2009-02-28 10:59:40 +08:00
|
|
|
class SingleObject(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-02-28 10:59:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2009-02-28 10:59:40 +08:00
|
|
|
class RelatedObject(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
single = models.ForeignKey(SingleObject, models.SET_NULL, null=True)
|
2012-08-25 21:33:07 +08:00
|
|
|
f = models.IntegerField(null=True)
|
2009-02-28 10:59:40 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['single']
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2009-02-28 10:59:40 +08:00
|
|
|
class Plaything(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
others = models.ForeignKey(RelatedObject, models.SET_NULL, null=True)
|
2009-02-28 10:59:40 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['others']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-02-28 10:59:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2010-10-19 12:07:22 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
created = models.DateTimeField()
|
2011-01-25 11:14:28 +08:00
|
|
|
|
2014-05-16 17:55:09 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-01-25 11:14:28 +08:00
|
|
|
class Food(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-01-25 11:14:28 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-01-25 11:14:28 +08:00
|
|
|
class Eaten(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
food = models.ForeignKey(Food, models.SET_NULL, to_field="name", null=True)
|
2011-01-25 11:14:28 +08:00
|
|
|
meal = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s at %s" % (self.food, self.meal)
|
2011-01-25 11:14:28 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-01-25 11:14:28 +08:00
|
|
|
class Node(models.Model):
|
|
|
|
num = models.IntegerField(unique=True)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey("self", models.SET_NULL, to_field="num", null=True)
|
2011-01-25 11:14:28 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2020-05-01 22:54:15 +08:00
|
|
|
return str(self.num)
|
2011-03-03 21:51:54 +08:00
|
|
|
|
|
|
|
# Bug #12252
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectA(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-03-03 21:51:54 +08:00
|
|
|
return self.name
|
|
|
|
|
2014-10-28 09:36:47 +08:00
|
|
|
def __iter__(self):
|
|
|
|
# Ticket #23721
|
|
|
|
assert False, 'type checking should happen without calling model __iter__'
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2014-06-14 15:24:19 +08:00
|
|
|
class ProxyObjectA(ObjectA):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
|
|
|
class ChildObjectA(ObjectA):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectB(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 22:43:21 +08:00
|
|
|
objecta = models.ForeignKey(ObjectA, models.CASCADE)
|
2011-03-09 03:26:32 +08:00
|
|
|
num = models.PositiveSmallIntegerField()
|
2011-03-03 21:51:54 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-03-03 21:51:54 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2014-06-14 15:24:19 +08:00
|
|
|
class ProxyObjectB(ObjectB):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectC(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 22:43:21 +08: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 21:51:54 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2013-09-04 02:22:21 +08:00
|
|
|
return self.name
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-08-23 11:38:42 +08:00
|
|
|
class SimpleCategory(models.Model):
|
2011-08-23 14:28:45 +08:00
|
|
|
name = models.CharField(max_length=15)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-08-23 11:38:42 +08:00
|
|
|
class SpecialCategory(SimpleCategory):
|
2011-08-23 14:28:45 +08:00
|
|
|
special_name = models.CharField(max_length=15)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return self.name + " " + self.special_name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-08-23 11:38:42 +08:00
|
|
|
class CategoryItem(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
category = models.ForeignKey(SimpleCategory, models.CASCADE)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-09-30 18:28:39 +08:00
|
|
|
return "category item: " + str(self.category)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2018-01-21 03:48:01 +08: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 11:38:42 +08:00
|
|
|
class OneToOneCategory(models.Model):
|
2011-08-23 14:28:45 +08:00
|
|
|
new_name = models.CharField(max_length=15)
|
2015-07-22 22:43:21 +08:00
|
|
|
category = models.OneToOneField(SimpleCategory, models.CASCADE)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return "one2one " + self.new_name
|
2012-04-29 18:45:46 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-09-30 01:02:25 +08:00
|
|
|
class CategoryRelationship(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
first = models.ForeignKey(SimpleCategory, models.CASCADE, related_name='first_rel')
|
|
|
|
second = models.ForeignKey(SimpleCategory, models.CASCADE, related_name='second_rel')
|
2013-09-30 01:02:25 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2018-01-21 03:48:01 +08: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 18:45:46 +08:00
|
|
|
class NullableName(models.Model):
|
|
|
|
name = models.CharField(max_length=20, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['id']
|
2012-08-21 23:43:08 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-21 23:43:08 +08:00
|
|
|
class ModelD(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-21 23:43:08 +08:00
|
|
|
class ModelC(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-21 23:43:08 +08:00
|
|
|
class ModelB(models.Model):
|
|
|
|
name = models.TextField()
|
2015-07-22 22:43:21 +08:00
|
|
|
c = models.ForeignKey(ModelC, models.CASCADE)
|
2012-08-21 23:43:08 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-21 23:43:08 +08:00
|
|
|
class ModelA(models.Model):
|
|
|
|
name = models.TextField()
|
2015-07-22 22:43:21 +08:00
|
|
|
b = models.ForeignKey(ModelB, models.SET_NULL, null=True)
|
|
|
|
d = models.ForeignKey(ModelD, models.CASCADE)
|
2012-08-25 21:33:07 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 21:33:07 +08:00
|
|
|
class Job(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 21:33:07 +08:00
|
|
|
class JobResponsibilities(models.Model):
|
2016-03-18 22:24:29 +08:00
|
|
|
job = models.ForeignKey(Job, models.CASCADE, to_field='name')
|
|
|
|
responsibility = models.ForeignKey('Responsibility', models.CASCADE, to_field='description')
|
2012-08-25 21:33:07 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 21:33:07 +08: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 19:13:37 +08:00
|
|
|
|
|
|
|
# Models for disjunction join promotion low level testing.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2012-08-25 19:13:37 +08:00
|
|
|
class FK1(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 19:13:37 +08:00
|
|
|
class FK2(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 19:13:37 +08:00
|
|
|
class FK3(models.Model):
|
|
|
|
f1 = models.TextField()
|
|
|
|
f2 = models.TextField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-08-25 19:13:37 +08:00
|
|
|
class BaseA(models.Model):
|
2015-07-22 22:43:21 +08: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-18 07:56:24 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-18 07:56:24 +08:00
|
|
|
class Identifier(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-18 07:56:24 +08:00
|
|
|
class Program(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
identifier = models.OneToOneField(Identifier, models.CASCADE)
|
2013-02-18 07:56:24 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-18 07:56:24 +08:00
|
|
|
class Channel(models.Model):
|
|
|
|
programs = models.ManyToManyField(Program)
|
2015-07-22 22:43:21 +08:00
|
|
|
identifier = models.OneToOneField(Identifier, models.CASCADE)
|
2013-02-28 21:04:12 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-28 21:04:12 +08:00
|
|
|
class Book(models.Model):
|
|
|
|
title = models.TextField()
|
2015-07-22 22:43:21 +08:00
|
|
|
chapter = models.ForeignKey('Chapter', models.CASCADE)
|
2013-02-28 21:04:12 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-28 21:04:12 +08:00
|
|
|
class Chapter(models.Model):
|
|
|
|
title = models.TextField()
|
2015-07-22 22:43:21 +08:00
|
|
|
paragraph = models.ForeignKey('Paragraph', models.CASCADE)
|
2013-02-28 21:04:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Paragraph(models.Model):
|
|
|
|
text = models.TextField()
|
|
|
|
page = models.ManyToManyField('Page')
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-28 21:04:12 +08:00
|
|
|
class Page(models.Model):
|
|
|
|
text = models.TextField()
|
2013-03-02 07:06:56 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-03-02 07:06:56 +08:00
|
|
|
class MyObject(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey('self', models.SET_NULL, null=True, blank=True, related_name='children')
|
2013-03-02 07:06:56 +08: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-25 05:27:24 +08:00
|
|
|
|
|
|
|
# Models for #17600 regressions
|
2013-11-03 05:34:05 +08: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-25 05:27:24 +08:00
|
|
|
class Order(models.Model):
|
|
|
|
id = models.IntegerField(primary_key=True)
|
2018-11-22 11:58:43 +08: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-25 05:27:24 +08:00
|
|
|
|
|
|
|
class Meta:
|
2017-12-29 04:07:29 +08: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-25 05:27:24 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-01 22:54:15 +08: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-25 05:27:24 +08:00
|
|
|
|
2013-11-03 05:34:05 +08: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-25 05:27:24 +08:00
|
|
|
class OrderItem(models.Model):
|
2016-03-18 22:24:29 +08: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-25 05:27:24 +08:00
|
|
|
status = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
2017-12-29 04:07:29 +08: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-25 05:27:24 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-01 22:54:15 +08:00
|
|
|
return str(self.pk)
|
2013-08-22 15:42:10 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-08-22 15:42:10 +08:00
|
|
|
class BaseUser(models.Model):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-08-22 15:42:10 +08:00
|
|
|
class Task(models.Model):
|
|
|
|
title = models.CharField(max_length=10)
|
2016-03-18 22:24:29 +08:00
|
|
|
owner = models.ForeignKey(BaseUser, models.CASCADE, related_name='owner')
|
|
|
|
creator = models.ForeignKey(BaseUser, models.CASCADE, related_name='creator')
|
2013-08-22 15:42:10 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-08-22 15:42:10 +08:00
|
|
|
class Staff(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-08-22 15:42:10 +08:00
|
|
|
class StaffUser(BaseUser):
|
2016-03-18 22:24:29 +08:00
|
|
|
staff = models.OneToOneField(Staff, models.CASCADE, related_name='user')
|
2013-08-22 15:42:10 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.staff
|
2013-10-01 16:07:41 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-10-01 16:07:41 +08: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-03 05:34:05 +08:00
|
|
|
|
2013-10-01 16:07:41 +08:00
|
|
|
class Ticket21203Child(models.Model):
|
|
|
|
childid = models.AutoField(primary_key=True)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(Ticket21203Parent, models.CASCADE)
|
2013-11-03 04:35:45 +08: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 22:43:21 +08:00
|
|
|
employer = models.ForeignKey(Company, models.CASCADE)
|
|
|
|
employee = models.ForeignKey(Person, models.CASCADE)
|
2013-11-03 04:35:45 +08:00
|
|
|
title = models.CharField(max_length=128)
|
2014-04-28 20:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
class School(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Student(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
school = models.ForeignKey(School, models.CASCADE)
|
2014-04-28 20:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Classroom(models.Model):
|
2016-10-27 06:01:37 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2017-05-06 22:56:28 +08:00
|
|
|
has_blackboard = models.BooleanField(null=True)
|
2015-07-22 22:43:21 +08:00
|
|
|
school = models.ForeignKey(School, models.CASCADE)
|
2014-04-28 20:27:36 +08:00
|
|
|
students = models.ManyToManyField(Student, related_name='classroom')
|
2014-10-07 21:07:46 +08:00
|
|
|
|
|
|
|
|
2017-03-02 22:36:25 +08:00
|
|
|
class Teacher(models.Model):
|
|
|
|
schools = models.ManyToManyField(School)
|
|
|
|
friends = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
|
2015-07-13 15:54:39 +08:00
|
|
|
class Ticket23605AParent(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605A(Ticket23605AParent):
|
2014-10-07 21:07:46 +08:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605B(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
modela_fk = models.ForeignKey(Ticket23605A, models.CASCADE)
|
|
|
|
modelc_fk = models.ForeignKey("Ticket23605C", models.CASCADE)
|
2014-10-07 21:07:46 +08:00
|
|
|
field_b0 = models.IntegerField(null=True)
|
|
|
|
field_b1 = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
|
|
class Ticket23605C(models.Model):
|
|
|
|
field_c0 = models.FloatField()
|
2015-04-16 13:39:31 +08: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 22:43:21 +08:00
|
|
|
related = models.ForeignKey(Individual, models.CASCADE, related_name='related_individual')
|
2015-04-16 13:39:31 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'RelatedIndividual'
|
2018-09-19 04:14:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CustomDbColumn(models.Model):
|
|
|
|
custom_column = models.IntegerField(db_column='custom_name', null=True)
|
|
|
|
ip_address = models.GenericIPAddressField(null=True)
|
2019-07-24 14:42:41 +08: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 08:56:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
class JSONFieldNullable(models.Model):
|
|
|
|
json_field = models.JSONField(blank=True, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {'supports_json_field'}
|