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.
|
|
|
|
"""
|
2012-06-07 18:08:47 +02:00
|
|
|
from __future__ import unicode_literals
|
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-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
|
2012-07-20 14:48:51 +02:00
|
|
|
from django.utils import six
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
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
|
|
|
|
2013-09-07 00:13:51 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
2008-06-29 05:01:46 +02:00
|
|
|
parent = models.ForeignKey('self', blank=True, null=True,
|
|
|
|
related_name='children')
|
2009-03-24 04:59:38 +01:00
|
|
|
category = models.ForeignKey(NamedCategory, 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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
|
|
|
|
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):
|
|
|
|
super(Note, self).__init__(*args, **kwargs)
|
|
|
|
# Regression for #13227 -- having an attribute that
|
|
|
|
# is unpickleable doesn't stop you from cloning queries
|
|
|
|
# that use objects of that type as an argument.
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-06-29 05:01:46 +02:00
|
|
|
class Annotation(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
tag = models.ForeignKey(Tag)
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
note = models.ForeignKey(Note)
|
2013-02-20 20:09:27 +01:00
|
|
|
value = 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
|
|
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
extra = models.ForeignKey(ExtraInfo)
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
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
|
|
|
tags = models.ManyToManyField(Tag, blank=True, null=True)
|
|
|
|
creator = models.ForeignKey(Author)
|
|
|
|
note = models.ForeignKey(Note)
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
2008-06-26 03:01:21 +02:00
|
|
|
creator = models.ForeignKey(Author, 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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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()
|
|
|
|
author = models.ForeignKey(Author)
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
item = models.ForeignKey(Item)
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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()
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2012-07-20 14:48:51 +02:00
|
|
|
return six.text_type(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
|
|
|
|
2008-06-26 12:50:25 +02:00
|
|
|
# Symmetrical m2m field with a normal field using the reverse accesor name
|
|
|
|
# ("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):
|
|
|
|
y = models.ForeignKey('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 Y(models.Model):
|
|
|
|
x1 = models.ForeignKey(X, related_name='y1')
|
|
|
|
|
|
|
|
# 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):
|
|
|
|
y = models.ForeignKey('LoopY')
|
|
|
|
|
|
|
|
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):
|
|
|
|
x = models.ForeignKey(LoopX)
|
|
|
|
|
|
|
|
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):
|
|
|
|
z = models.ForeignKey('self')
|
|
|
|
|
|
|
|
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):
|
|
|
|
qs = super(CustomManager, self).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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-04-28 13:51:16 +02:00
|
|
|
class ManagedModel(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
tag = models.ForeignKey(Tag)
|
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):
|
|
|
|
return super(MemberManager, self).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)
|
|
|
|
details = models.OneToOneField(Detail, primary_key=True)
|
|
|
|
|
|
|
|
objects = MemberManager()
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2008-06-26 03:02:11 +02:00
|
|
|
class Child(models.Model):
|
|
|
|
person = models.OneToOneField(Member, primary_key=True)
|
|
|
|
parent = models.ForeignKey(Member, related_name="children")
|
|
|
|
|
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):
|
|
|
|
custom = models.ForeignKey(CustomPk)
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-07-27 06:18:52 +02:00
|
|
|
class Celebrity(models.Model):
|
|
|
|
name = models.CharField("Name", max_length=20)
|
|
|
|
greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
|
|
|
|
|
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):
|
|
|
|
fan_of = models.ForeignKey(Celebrity)
|
|
|
|
|
2008-07-27 20:16:17 +02:00
|
|
|
# Multiple foreign keys
|
2013-11-02 22:34:05 +01:00
|
|
|
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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):
|
|
|
|
a = models.ForeignKey(LeafA)
|
|
|
|
b = models.ForeignKey(LeafB)
|
2008-04-28 13:51:16 +02:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
|
|
|
|
2013-08-20 10:33:44 +02:00
|
|
|
@python_2_unicode_compatible
|
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):
|
|
|
|
connection = models.ForeignKey(SharedConnection)
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2008-12-07 06:48:01 +01:00
|
|
|
class PointerB(models.Model):
|
|
|
|
connection = models.ForeignKey(SharedConnection)
|
|
|
|
|
2009-02-28 03:59:40 +01:00
|
|
|
# Multi-layer ordering
|
2013-11-02 22:34:05 +01:00
|
|
|
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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):
|
2012-05-23 22:25:23 +02:00
|
|
|
single = models.ForeignKey(SingleObject, 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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-02-28 03:59:40 +01:00
|
|
|
class Plaything(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
others = models.ForeignKey(RelatedObject, null=True)
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 04:14:28 +01:00
|
|
|
class Eaten(models.Model):
|
2012-08-25 15:33:07 +02:00
|
|
|
food = models.ForeignKey(Food, 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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 04:14:28 +01:00
|
|
|
class Node(models.Model):
|
|
|
|
num = models.IntegerField(unique=True)
|
|
|
|
parent = models.ForeignKey("self", to_field="num", null=True)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-03-03 14:51:54 +01:00
|
|
|
class ObjectB(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
objecta = models.ForeignKey(ObjectA)
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-03-03 14:51:54 +01:00
|
|
|
class ObjectC(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2013-11-04 17:04:57 +01:00
|
|
|
objecta = models.ForeignKey(ObjectA, null=True)
|
|
|
|
objectb = models.ForeignKey(ObjectB, null=True)
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-08-23 05:38:42 +02:00
|
|
|
class CategoryItem(models.Model):
|
|
|
|
category = models.ForeignKey(SimpleCategory)
|
|
|
|
|
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
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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)
|
2011-08-23 05:38:42 +02:00
|
|
|
category = models.OneToOneField(SimpleCategory)
|
|
|
|
|
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):
|
|
|
|
first = models.ForeignKey(SimpleCategory, related_name='first_rel')
|
|
|
|
second = models.ForeignKey(SimpleCategory, related_name='second_rel')
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
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()
|
|
|
|
c = models.ForeignKey(ModelC)
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-21 17:43:08 +02:00
|
|
|
class ModelA(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
b = models.ForeignKey(ModelB, null=True)
|
|
|
|
d = models.ForeignKey(ModelD)
|
2012-08-25 15:33:07 +02:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-25 15:33:07 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
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):
|
|
|
|
job = models.ForeignKey(Job, to_field='name')
|
|
|
|
responsibility = models.ForeignKey('Responsibility', to_field='description')
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-08-25 15:33:07 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
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):
|
|
|
|
a = models.ForeignKey(FK1, null=True)
|
|
|
|
b = models.ForeignKey(FK2, null=True)
|
|
|
|
c = models.ForeignKey(FK3, 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
|
|
|
@python_2_unicode_compatible
|
|
|
|
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):
|
|
|
|
identifier = models.OneToOneField(Identifier)
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2013-02-18 00:56:24 +01:00
|
|
|
class Channel(models.Model):
|
|
|
|
programs = models.ManyToManyField(Program)
|
|
|
|
identifier = models.OneToOneField(Identifier)
|
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()
|
|
|
|
chapter = models.ForeignKey('Chapter')
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2013-02-28 14:04:12 +01:00
|
|
|
class Chapter(models.Model):
|
|
|
|
title = models.TextField()
|
|
|
|
paragraph = models.ForeignKey('Paragraph')
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
|
|
|
|
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
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Order(models.Model):
|
|
|
|
id = models.IntegerField(primary_key=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('pk', )
|
|
|
|
|
|
|
|
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
|
|
|
@python_2_unicode_compatible
|
|
|
|
class OrderItem(models.Model):
|
|
|
|
order = models.ForeignKey(Order, related_name='items')
|
|
|
|
status = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('pk', )
|
|
|
|
|
|
|
|
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
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Task(models.Model):
|
|
|
|
title = models.CharField(max_length=10)
|
|
|
|
owner = models.ForeignKey(BaseUser, related_name='owner')
|
|
|
|
creator = models.ForeignKey(BaseUser, related_name='creator')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2013-08-22 09:42:10 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
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
|
|
|
@python_2_unicode_compatible
|
|
|
|
class StaffUser(BaseUser):
|
|
|
|
staff = models.OneToOneField(Staff, related_name='user')
|
|
|
|
|
|
|
|
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)
|
|
|
|
parent = models.ForeignKey(Ticket21203Parent)
|
2013-11-02 21:35:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
|
|
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):
|
|
|
|
employer = models.ForeignKey(Company)
|
|
|
|
employee = models.ForeignKey(Person)
|
|
|
|
title = models.CharField(max_length=128)
|