2007-03-13 01:03:05 +00:00
|
|
|
"""
|
|
|
|
A test spanning all the capabilities of all the serializers.
|
|
|
|
|
2007-05-21 01:29:58 +00:00
|
|
|
This class sets up a model for each model field type
|
2014-03-21 14:54:53 +00:00
|
|
|
(except for image types, because of the Pillow dependency).
|
2007-03-13 01:03:05 +00:00
|
|
|
"""
|
2014-01-22 06:43:33 +00:00
|
|
|
from django.contrib.contenttypes.fields import (
|
2015-01-28 12:35:27 +00:00
|
|
|
GenericForeignKey, GenericRelation,
|
2014-01-22 06:43:33 +00:00
|
|
|
)
|
2007-03-19 11:57:53 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2007-03-19 11:57:53 +00:00
|
|
|
|
2007-05-21 01:29:58 +00:00
|
|
|
# The following classes are for testing basic data
|
2009-04-09 15:09:35 +00:00
|
|
|
# marshalling, including NULL values, where allowed.
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-12-14 23:26:08 +00:00
|
|
|
class BinaryData(models.Model):
|
|
|
|
data = models.BinaryField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class BooleanData(models.Model):
|
2013-08-11 20:19:09 +00:00
|
|
|
data = models.BooleanField(default=False)
|
2007-05-21 01:29:58 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class CharData(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
data = models.CharField(max_length=30, null=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class DateData(models.Model):
|
|
|
|
data = models.DateField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class DateTimeData(models.Model):
|
|
|
|
data = models.DateTimeField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-05-21 01:29:58 +00:00
|
|
|
class DecimalData(models.Model):
|
|
|
|
data = models.DecimalField(null=True, decimal_places=3, max_digits=5)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class EmailData(models.Model):
|
|
|
|
data = models.EmailField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FileData(models.Model):
|
|
|
|
data = models.FileField(null=True, upload_to='/foo/bar')
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FilePathData(models.Model):
|
|
|
|
data = models.FilePathField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FloatData(models.Model):
|
2007-05-21 01:29:58 +00:00
|
|
|
data = models.FloatField(null=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class IntegerData(models.Model):
|
|
|
|
data = models.IntegerField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2009-12-17 15:10:38 +00:00
|
|
|
class BigIntegerData(models.Model):
|
|
|
|
data = models.BigIntegerField(null=True)
|
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
# class ImageData(models.Model):
|
|
|
|
# data = models.ImageField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-06-11 13:48:24 +00:00
|
|
|
class GenericIPAddressData(models.Model):
|
|
|
|
data = models.GenericIPAddressField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class NullBooleanData(models.Model):
|
|
|
|
data = models.NullBooleanField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class PositiveIntegerData(models.Model):
|
|
|
|
data = models.PositiveIntegerField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class PositiveSmallIntegerData(models.Model):
|
|
|
|
data = models.PositiveSmallIntegerField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class SlugData(models.Model):
|
|
|
|
data = models.SlugField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class SmallData(models.Model):
|
|
|
|
data = models.SmallIntegerField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class TextData(models.Model):
|
|
|
|
data = models.TextField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class TimeData(models.Model):
|
|
|
|
data = models.TimeField(null=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-19 11:57:53 +00:00
|
|
|
class Tag(models.Model):
|
|
|
|
"""A tag on an item."""
|
|
|
|
data = models.SlugField()
|
2015-07-22 14:43:21 +00:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2007-03-19 11:57:53 +00:00
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
|
2014-01-22 06:43:33 +00:00
|
|
|
content_object = GenericForeignKey()
|
2007-03-19 11:57:53 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["data"]
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-19 11:57:53 +00:00
|
|
|
class GenericData(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
data = models.CharField(max_length=30)
|
2007-03-19 11:57:53 +00:00
|
|
|
|
2014-01-22 06:43:33 +00:00
|
|
|
tags = GenericRelation(Tag)
|
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 02:50:16 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
# The following test classes are all for validation
|
|
|
|
# of related objects; in particular, forward, backward,
|
|
|
|
# and self references.
|
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 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class Anchor(models.Model):
|
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 02:50:16 +00:00
|
|
|
"""This is a model that can be used as
|
2007-03-13 01:03:05 +00:00
|
|
|
something for other models to point at"""
|
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 02:50:16 +00:00
|
|
|
|
2007-08-05 05:14:46 +00:00
|
|
|
data = models.CharField(max_length=30)
|
2007-05-14 14:21:00 +00:00
|
|
|
|
2009-11-03 14:02:49 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-03-12 19:41:31 +00:00
|
|
|
class NaturalKeyAnchorManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, data):
|
|
|
|
return self.get(data=data)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-03-12 19:41:31 +00:00
|
|
|
class NaturalKeyAnchor(models.Model):
|
|
|
|
objects = NaturalKeyAnchorManager()
|
|
|
|
|
|
|
|
data = models.CharField(max_length=100, unique=True)
|
2012-08-01 01:49:01 +00:00
|
|
|
title = models.CharField(max_length=100, null=True)
|
2012-03-12 19:41:31 +00:00
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.data,)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-05-14 14:21:00 +00:00
|
|
|
class UniqueAnchor(models.Model):
|
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 02:50:16 +00:00
|
|
|
"""This is a model that can be used as
|
2007-05-14 14:21:00 +00:00
|
|
|
something for other models to point at"""
|
|
|
|
|
2007-08-05 05:14:46 +00:00
|
|
|
data = models.CharField(unique=True, max_length=30)
|
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 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FKData(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey(Anchor, models.SET_NULL, null=True)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-03-12 19:41:31 +00:00
|
|
|
class FKDataNaturalKey(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey(NaturalKeyAnchor, models.SET_NULL, null=True)
|
2012-03-12 19:41:31 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class M2MData(models.Model):
|
2014-07-08 20:42:40 +00:00
|
|
|
data = models.ManyToManyField(Anchor)
|
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 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class O2OData(models.Model):
|
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 02:50:16 +00:00
|
|
|
# One to one field can't be null here, since it is a PK.
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.OneToOneField(Anchor, models.CASCADE, primary_key=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FKSelfData(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey('self', models.CASCADE, 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 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class M2MSelfData(models.Model):
|
2014-07-08 20:42:40 +00:00
|
|
|
data = models.ManyToManyField('self', symmetrical=False)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-05-14 14:14:49 +00:00
|
|
|
class FKDataToField(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey(UniqueAnchor, models.SET_NULL, null=True, to_field='data')
|
2007-05-14 14:14:49 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-05-28 05:41:32 +00:00
|
|
|
class FKDataToO2O(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey(O2OData, models.SET_NULL, null=True)
|
2007-05-28 05:41:32 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-08-12 12:58:33 +00:00
|
|
|
class M2MIntermediateData(models.Model):
|
2014-07-08 20:42:40 +00:00
|
|
|
data = models.ManyToManyField(Anchor, through='Intermediate')
|
2009-11-03 14:02:49 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-08-12 12:58:33 +00:00
|
|
|
class Intermediate(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
left = models.ForeignKey(M2MIntermediateData, models.CASCADE)
|
|
|
|
right = models.ForeignKey(Anchor, models.CASCADE)
|
2008-08-12 12:58:33 +00:00
|
|
|
extra = models.CharField(max_length=30, blank=True, default="doesn't matter")
|
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
# The following test classes are for validating the
|
|
|
|
# deserialization of objects that use a user-defined
|
|
|
|
# field as the primary key.
|
|
|
|
# Some of these data types have been commented out
|
|
|
|
# because they can't be used as a primary key on one
|
|
|
|
# or all database backends.
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class BooleanPKData(models.Model):
|
2013-08-11 20:19:09 +00:00
|
|
|
data = models.BooleanField(primary_key=True, default=False)
|
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 02:50:16 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class CharPKData(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
data = models.CharField(max_length=30, primary_key=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
|
|
|
# class DatePKData(models.Model):
|
|
|
|
# data = models.DateField(primary_key=True)
|
|
|
|
|
|
|
|
# class DateTimePKData(models.Model):
|
|
|
|
# data = models.DateTimeField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-05-21 01:29:58 +00:00
|
|
|
class DecimalPKData(models.Model):
|
|
|
|
data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class EmailPKData(models.Model):
|
|
|
|
data = models.EmailField(primary_key=True)
|
|
|
|
|
2008-08-08 20:59:02 +00:00
|
|
|
# class FilePKData(models.Model):
|
|
|
|
# data = models.FileField(primary_key=True, upload_to='/foo/bar')
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FilePathPKData(models.Model):
|
|
|
|
data = models.FilePathField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class FloatPKData(models.Model):
|
2007-05-21 01:29:58 +00:00
|
|
|
data = models.FloatField(primary_key=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class IntegerPKData(models.Model):
|
|
|
|
data = models.IntegerField(primary_key=True)
|
|
|
|
|
|
|
|
# class ImagePKData(models.Model):
|
|
|
|
# data = models.ImageField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-06-11 13:48:24 +00:00
|
|
|
class GenericIPAddressPKData(models.Model):
|
|
|
|
data = models.GenericIPAddressField(primary_key=True)
|
|
|
|
|
2007-07-12 11:27:38 +00:00
|
|
|
# This is just a Boolean field with null=True, and we can't test a PK value of NULL.
|
|
|
|
# class NullBooleanPKData(models.Model):
|
|
|
|
# data = models.NullBooleanField(primary_key=True)
|
2007-03-13 01:03:05 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class PositiveIntegerPKData(models.Model):
|
|
|
|
data = models.PositiveIntegerField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class PositiveSmallIntegerPKData(models.Model):
|
|
|
|
data = models.PositiveSmallIntegerField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class SlugPKData(models.Model):
|
|
|
|
data = models.SlugField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-03-13 01:03:05 +00:00
|
|
|
class SmallPKData(models.Model):
|
|
|
|
data = models.SmallIntegerField(primary_key=True)
|
|
|
|
|
|
|
|
# class TextPKData(models.Model):
|
|
|
|
# data = models.TextField(primary_key=True)
|
|
|
|
|
|
|
|
# class TimePKData(models.Model):
|
|
|
|
# data = models.TimeField(primary_key=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-02-12 14:54:42 +00:00
|
|
|
class UUIDData(models.Model):
|
|
|
|
data = models.UUIDField(primary_key=True)
|
|
|
|
|
|
|
|
|
2015-02-13 14:21:33 +00:00
|
|
|
class FKToUUID(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
data = models.ForeignKey(UUIDData, models.CASCADE)
|
2015-02-13 14:21:33 +00:00
|
|
|
|
|
|
|
|
2007-06-01 13:39:08 +00:00
|
|
|
class ComplexModel(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
field1 = models.CharField(max_length=10)
|
|
|
|
field2 = models.CharField(max_length=10)
|
|
|
|
field3 = models.CharField(max_length=10)
|
2007-07-12 07:45:35 +00:00
|
|
|
|
|
|
|
# Tests for handling fields with pre_save functions, or
|
|
|
|
# models with save functions that modify data
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2007-07-12 07:45:35 +00:00
|
|
|
class AutoNowDateTimeData(models.Model):
|
|
|
|
data = models.DateTimeField(null=True, auto_now=True)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2007-07-12 07:45:35 +00:00
|
|
|
class ModifyingSaveData(models.Model):
|
|
|
|
data = models.IntegerField(null=True)
|
|
|
|
|
2013-10-10 16:59:55 +00:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
A save method that modifies the data in the object.
|
|
|
|
Verifies that a user-defined save() method isn't called when objects
|
|
|
|
are deserialized (#4459).
|
|
|
|
"""
|
2007-07-12 07:45:35 +00:00
|
|
|
self.data = 666
|
2013-10-10 16:59:55 +00:00
|
|
|
super(ModifyingSaveData, self).save(*args, **kwargs)
|
2008-06-09 14:03:35 +00:00
|
|
|
|
|
|
|
# Tests for serialization of models using inheritance.
|
|
|
|
# Regression for #7202, #7350
|
2013-11-02 21:34:05 +00:00
|
|
|
|
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class AbstractBaseModel(models.Model):
|
|
|
|
parent_data = models.IntegerField()
|
2013-10-22 10:21:07 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class InheritAbstractModel(AbstractBaseModel):
|
|
|
|
child_data = models.IntegerField()
|
2009-11-03 14:02:49 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class BaseModel(models.Model):
|
|
|
|
parent_data = models.IntegerField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class InheritBaseModel(BaseModel):
|
|
|
|
child_data = models.IntegerField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
class ExplicitInheritBaseModel(BaseModel):
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.OneToOneField(BaseModel, models.CASCADE)
|
2008-06-09 14:03:35 +00:00
|
|
|
child_data = models.IntegerField()
|
2010-02-24 15:54:03 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-03-03 17:50:18 +00:00
|
|
|
class ProxyBaseModel(BaseModel):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-03-03 21:34:51 +00:00
|
|
|
class ProxyProxyBaseModel(ProxyBaseModel):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-02-24 15:54:03 +00:00
|
|
|
class LengthModel(models.Model):
|
|
|
|
data = models.IntegerField()
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.data
|