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