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
|
|
|
|
|
2012-05-09 19:33:31 +02:00
|
|
|
class ProxyCategory(DumbCategory):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2009-03-24 04:59:38 +01:00
|
|
|
class NamedCategory(DumbCategory):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
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
|
|
|
|
|
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()
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
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
|
|
|
|
|
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").
|
|
|
|
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.
|
|
|
|
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 13:51:16 +02:00
|
|
|
# A model and custom default manager combination.
|
|
|
|
class CustomManager(models.Manager):
|
|
|
|
def get_query_set(self):
|
2008-04-28 19:31:08 +02:00
|
|
|
qs = super(CustomManager, self).get_query_set()
|
2008-06-26 05:11:32 +02:00
|
|
|
return qs.filter(public=True, tag__name='t1')
|
2008-04-28 13:51:16 +02: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.
|
|
|
|
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 13:15:48 +02: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 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.
|
|
|
|
|
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
|
|
|
|
|
2008-07-27 06:18:52 +02:00
|
|
|
class TvChef(Celebrity):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Fan(models.Model):
|
|
|
|
fan_of = models.ForeignKey(Celebrity)
|
|
|
|
|
2008-07-27 20:16:17 +02:00
|
|
|
# Multiple foreign keys
|
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
|
|
|
|
|
|
|
|
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 13:51:16 +02: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.
|
|
|
|
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 03:59:40 +01:00
|
|
|
# Multi-layer ordering
|
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
|
|
|
|
|
|
|
|
class RelatedObject(models.Model):
|
2012-05-23 22:25:23 +02:00
|
|
|
single = models.ForeignKey(SingleObject, null=True)
|
2009-02-28 03:59:40 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['single']
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2011-01-25 04:14:28 +01:00
|
|
|
class Eaten(models.Model):
|
|
|
|
food = models.ForeignKey(Food, to_field="name")
|
|
|
|
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
|
|
|
|
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
|
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
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
objecta = models.ForeignKey(ObjectA)
|
|
|
|
objectb = models.ForeignKey(ObjectB)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2011-03-03 14:51:54 +01:00
|
|
|
return self.name
|
2011-08-23 05:38:42 +02: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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
class NullableName(models.Model):
|
|
|
|
name = models.CharField(max_length=20, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['id']
|
2012-08-21 17:43:08 +02:00
|
|
|
|
|
|
|
class ModelD(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
|
|
|
class ModelC(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
|
|
|
class ModelB(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
c = models.ForeignKey(ModelC)
|
|
|
|
|
|
|
|
class ModelA(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
b = models.ForeignKey(ModelB, null=True)
|
|
|
|
d = models.ForeignKey(ModelD)
|