Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
|
|
|
Various complex queries that have been problematic in the past.
|
|
|
|
"""
|
2012-06-08 00:08:47 +08: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 10:50:16 +08:00
|
|
|
|
2010-03-27 23:16:27 +08:00
|
|
|
import threading
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2010-10-19 12:07:22 +08:00
|
|
|
from django.db import models
|
2012-07-20 20:48:51 +08:00
|
|
|
from django.utils import six
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class DumbCategory(models.Model):
|
|
|
|
pass
|
|
|
|
|
2012-05-10 01:33:31 +08:00
|
|
|
class ProxyCategory(DumbCategory):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class NamedCategory(DumbCategory):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2008-06-29 11:01:46 +08:00
|
|
|
parent = models.ForeignKey('self', blank=True, null=True,
|
|
|
|
related_name='children')
|
2009-03-24 11:59:38 +08: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 10:50:16 +08:00
|
|
|
|
2008-08-15 11:36:18 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Note(models.Model):
|
|
|
|
note = models.CharField(max_length=100)
|
|
|
|
misc = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['note']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.note
|
|
|
|
|
2010-03-27 23:16:27 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
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()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-06-29 11:01:46 +08:00
|
|
|
class Annotation(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
tag = models.ForeignKey(Tag)
|
|
|
|
notes = models.ManyToManyField(Note)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-06-29 11:01:46 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class ExtraInfo(models.Model):
|
|
|
|
info = models.CharField(max_length=100)
|
|
|
|
note = models.ForeignKey(Note)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['info']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.info
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
num = models.IntegerField(unique=True)
|
|
|
|
extra = models.ForeignKey(ExtraInfo)
|
|
|
|
|
2009-08-21 00:05:25 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
created = models.DateTimeField()
|
2008-06-25 21:38:06 +08:00
|
|
|
modified = models.DateTimeField(blank=True, null=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
tags = models.ManyToManyField(Tag, blank=True, null=True)
|
|
|
|
creator = models.ForeignKey(Author)
|
|
|
|
note = models.ForeignKey(Note)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['-note', 'name']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Report(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2008-06-26 09:01:21 +08: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 10:50:16 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08: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 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return '%d: %s' % (self.rank, self.author.name)
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Cover(models.Model):
|
|
|
|
title = models.CharField(max_length=50)
|
|
|
|
item = models.ForeignKey(Item)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['item']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return self.title
|
|
|
|
|
2012-08-12 18:32:08 +08: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 10:50:16 +08:00
|
|
|
class Number(models.Model):
|
|
|
|
num = models.IntegerField()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-07-20 20:48:51 +08: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 10:50:16 +08:00
|
|
|
|
2008-06-26 18:50:25 +08:00
|
|
|
# Symmetrical m2m field with a normal field using the reverse accesor name
|
|
|
|
# ("valid").
|
|
|
|
class Valid(models.Model):
|
|
|
|
valid = models.CharField(max_length=10)
|
|
|
|
parent = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['valid']
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
# Some funky cross-linked models for testing a couple of infinite recursion
|
|
|
|
# cases.
|
|
|
|
class X(models.Model):
|
|
|
|
y = models.ForeignKey('Y')
|
|
|
|
|
|
|
|
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.
|
|
|
|
class LoopX(models.Model):
|
|
|
|
y = models.ForeignKey('LoopY')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['y']
|
|
|
|
|
|
|
|
class LoopY(models.Model):
|
|
|
|
x = models.ForeignKey(LoopX)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['x']
|
|
|
|
|
|
|
|
class LoopZ(models.Model):
|
|
|
|
z = models.ForeignKey('self')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['z']
|
|
|
|
|
2008-04-28 19:51:16 +08:00
|
|
|
# A model and custom default manager combination.
|
|
|
|
class CustomManager(models.Manager):
|
|
|
|
def get_query_set(self):
|
2008-04-29 01:31:08 +08:00
|
|
|
qs = super(CustomManager, self).get_query_set()
|
2008-06-26 11:11:32 +08:00
|
|
|
return qs.filter(public=True, tag__name='t1')
|
2008-04-28 19:51:16 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-04-28 19:51:16 +08:00
|
|
|
class ManagedModel(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
tag = models.ForeignKey(Tag)
|
2008-06-26 11:11:32 +08:00
|
|
|
public = models.BooleanField(default=True)
|
2008-04-28 19:51:16 +08:00
|
|
|
|
|
|
|
objects = CustomManager()
|
|
|
|
normal_manager = models.Manager()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-04-28 19:51:16 +08:00
|
|
|
return self.data
|
|
|
|
|
2008-06-26 09:02:11 +08:00
|
|
|
# An inter-related setup with multiple paths from Child to Detail.
|
|
|
|
class Detail(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class MemberManager(models.Manager):
|
|
|
|
def get_query_set(self):
|
|
|
|
return super(MemberManager, self).get_query_set().select_related("details")
|
|
|
|
|
|
|
|
class Member(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
details = models.OneToOneField(Detail, primary_key=True)
|
|
|
|
|
|
|
|
objects = MemberManager()
|
|
|
|
|
|
|
|
class Child(models.Model):
|
|
|
|
person = models.OneToOneField(Member, primary_key=True)
|
|
|
|
parent = models.ForeignKey(Member, related_name="children")
|
|
|
|
|
2008-06-29 19:15:48 +08:00
|
|
|
# Custom primary keys interfered with ordering in the past.
|
|
|
|
class CustomPk(models.Model):
|
|
|
|
name = models.CharField(max_length=10, primary_key=True)
|
|
|
|
extra = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name', 'extra']
|
|
|
|
|
|
|
|
class Related(models.Model):
|
|
|
|
custom = models.ForeignKey(CustomPk)
|
|
|
|
|
2008-07-27 12:18:52 +08:00
|
|
|
# An inter-related setup with a model subclass that has a nullable
|
|
|
|
# path to another model, and a return path from that model.
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-27 12:18:52 +08:00
|
|
|
class Celebrity(models.Model):
|
|
|
|
name = models.CharField("Name", max_length=20)
|
|
|
|
greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-23 04:42:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2008-07-27 12:18:52 +08:00
|
|
|
class TvChef(Celebrity):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Fan(models.Model):
|
|
|
|
fan_of = models.ForeignKey(Celebrity)
|
|
|
|
|
2008-07-28 02:16:17 +08:00
|
|
|
# Multiple foreign keys
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-28 02:16:17 +08:00
|
|
|
class LeafA(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-07-28 02:16:17 +08:00
|
|
|
return self.data
|
|
|
|
|
|
|
|
class LeafB(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Join(models.Model):
|
|
|
|
a = models.ForeignKey(LeafA)
|
|
|
|
b = models.ForeignKey(LeafB)
|
2008-04-28 19:51:16 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-09-01 20:07:26 +08:00
|
|
|
class ReservedName(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
order = models.IntegerField()
|
2008-09-02 10:16:41 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-09-01 20:07:26 +08:00
|
|
|
return self.name
|
2008-09-02 10:16:41 +08:00
|
|
|
|
2008-12-07 13:48:01 +08:00
|
|
|
# A simpler shared-foreign-key setup that can expose some problems.
|
|
|
|
class SharedConnection(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class PointerA(models.Model):
|
|
|
|
connection = models.ForeignKey(SharedConnection)
|
|
|
|
|
|
|
|
class PointerB(models.Model):
|
|
|
|
connection = models.ForeignKey(SharedConnection)
|
|
|
|
|
2009-02-28 10:59:40 +08:00
|
|
|
# Multi-layer ordering
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-02-28 10:59:40 +08:00
|
|
|
class SingleObject(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-02-28 10:59:40 +08:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
class RelatedObject(models.Model):
|
2012-05-24 04:25:23 +08:00
|
|
|
single = models.ForeignKey(SingleObject, null=True)
|
2009-02-28 10:59:40 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['single']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-02-28 10:59:40 +08:00
|
|
|
class Plaything(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
others = models.ForeignKey(RelatedObject, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['others']
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-02-28 10:59:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2010-10-19 12:07:22 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
created = models.DateTimeField()
|
2011-01-25 11:14:28 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 11:14:28 +08:00
|
|
|
class Food(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-01-25 11:14:28 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 11:14:28 +08:00
|
|
|
class Eaten(models.Model):
|
|
|
|
food = models.ForeignKey(Food, to_field="name")
|
|
|
|
meal = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s at %s" % (self.food, self.meal)
|
2011-01-25 11:14:28 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 11:14:28 +08:00
|
|
|
class Node(models.Model):
|
|
|
|
num = models.IntegerField(unique=True)
|
|
|
|
parent = models.ForeignKey("self", to_field="num", null=True)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s" % self.num
|
2011-03-03 21:51:54 +08:00
|
|
|
|
|
|
|
# Bug #12252
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectA(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-03-03 21:51:54 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectB(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
objecta = models.ForeignKey(ObjectA)
|
2011-03-09 03:26:32 +08:00
|
|
|
num = models.PositiveSmallIntegerField()
|
2011-03-03 21:51:54 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-03-03 21:51:54 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-03-03 21:51:54 +08:00
|
|
|
class ObjectC(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
objecta = models.ForeignKey(ObjectA)
|
|
|
|
objectb = models.ForeignKey(ObjectB)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-03-03 21:51:54 +08:00
|
|
|
return self.name
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-08-23 11:38:42 +08:00
|
|
|
class SimpleCategory(models.Model):
|
2011-08-23 14:28:45 +08:00
|
|
|
name = models.CharField(max_length=15)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-08-23 11:38:42 +08:00
|
|
|
class SpecialCategory(SimpleCategory):
|
2011-08-23 14:28:45 +08:00
|
|
|
special_name = models.CharField(max_length=15)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return self.name + " " + self.special_name
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-08-23 11:38:42 +08:00
|
|
|
class CategoryItem(models.Model):
|
|
|
|
category = models.ForeignKey(SimpleCategory)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-09-30 18:28:39 +08:00
|
|
|
return "category item: " + str(self.category)
|
2011-08-23 11:38:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-08-23 11:38:42 +08:00
|
|
|
class OneToOneCategory(models.Model):
|
2011-08-23 14:28:45 +08:00
|
|
|
new_name = models.CharField(max_length=15)
|
2011-08-23 11:38:42 +08:00
|
|
|
category = models.OneToOneField(SimpleCategory)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-08-23 11:38:42 +08:00
|
|
|
return "one2one " + self.new_name
|
2012-04-29 18:45:46 +08:00
|
|
|
|
|
|
|
class NullableName(models.Model):
|
|
|
|
name = models.CharField(max_length=20, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['id']
|