models for testdata py the following classes are for testing basic data marshalling including null values where allowed the basic idea is to have a model for each django data type class imagedatamodels model data models imagefieldnulltrue a tag on an item data models slugfield contenttype models foreignkeycontenttype models cascade objectid models positiveintegerfield contentobject genericforeignkey class meta ordering data class genericdatamodels model data models charfieldmaxlength30 tags genericrelationtag the following test classes are all for validation of related objects in particular forward backward and self references class anchormodels model this is a model that can be used as something for other models to point at data models charfielduniquetrue maxlength30 class fkdatamodels model data models foreignkeyanchor models setnull nulltrue class m2mdatamodels model data models manytomanyfieldanchor class o2odatamodels model one to one field can t be null here since it is a pk data models onetoonefieldanchor models cascade primarykeytrue class fkselfdatamodels model data models foreignkeyself models cascade nulltrue class m2mselfdatamodels model data models manytomanyfieldself symmetricalfalse class fkdatatofieldmodels model data models foreignkeyuniqueanchor models setnull nulltrue tofielddata class fkdatatoo2omodels model data models foreignkeyo2odata models setnull nulltrue class m2mintermediatedatamodels model data models manytomanyfieldanchor throughintermediate class intermediatemodels model left models foreignkeym2mintermediatedata models cascade right models foreignkeyanchor models cascade extra models charfieldmaxlength30 blanktrue defaultdoesn t matter the following test classes are for validating the deserialization of objects that use a userdefined 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 class booleanpkdatamodels model data models booleanfieldprimarykeytrue defaultfalse class charpkdatamodels model data models charfieldmaxlength30 primarykeytrue class datepkdatamodels model data models datefieldprimarykeytrue class datetimepkdatamodels model data models datetimefieldprimarykeytrue class decimalpkdatamodels model data models decimalfieldprimarykeytrue decimalplaces3 maxdigits5 class emailpkdatamodels model data models emailfieldprimarykeytrue class filepkdatamodels model data models filefieldprimarykeytrue class filepathpkdatamodels model data models filepathfieldprimarykeytrue class floatpkdatamodels model data models floatfieldprimarykeytrue class integerpkdatamodels model data models integerfieldprimarykeytrue class imagepkdatamodels model data models imagefieldprimarykeytrue class genericipaddresspkdatamodels model data models genericipaddressfieldprimarykeytrue class positiveintegerpkdatamodels model data models positiveintegerfieldprimarykeytrue class positivesmallintegerpkdatamodels model data models positivesmallintegerfieldprimarykeytrue class slugpkdatamodels model data models slugfieldprimarykeytrue class smallpkdatamodels model data models smallintegerfieldprimarykeytrue class textpkdatamodels model data models textfieldprimarykeytrue class timepkdatamodels model data models timefieldprimarykeytrue class uuiddatamodels model data models uuidfieldprimarykeytrue class uuiddefaultdatamodels model data models uuidfieldprimarykeytrue defaultuuid uuid4 class fktouuidmodels model data models foreignkeyuuiddata models cascade tests for handling fields with presave functions or models with save functions that modify data class autonowdatetimedatamodels model data models datetimefieldnulltrue autonowtrue class modifyingsavedatamodels model data models integerfieldnulltrue def saveself args kwargs self data 666 super saveargs kwargs tests for serialization of models using inheritance regression for 7202 7350 class abstractbasemodelmodels model parentdata models integerfield class meta abstract true class inheritabstractmodelabstractbasemodel childdata models integerfield class inheritbasemodelbasemodel childdata models integerfield class explicitinheritbasemodelbasemodel parent models onetoonefieldbasemodel models cascade parentlinktrue childdata models integerfield class lengthmodelmodels model data models integerfield def lenself return self data class imagedata models model data models imagefield null true a tag on an item the following test classes are all for validation of related objects in particular forward backward and self references this is a model that can be used as something for other models to point at this is a model that can be used as something for other models to point at one to one field can t be null here since it is a pk 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 class filepkdata models model data models filefield primary_key true class imagepkdata models model data models imagefield primary_key true class textpkdata models model data models textfield primary_key true class timepkdata models model data models timefield primary_key true tests for handling fields with pre_save functions or models with save functions that modify data a save method that modifies the data in the object a user defined save method isn t called when objects are deserialized 4459 tests for serialization of models using inheritance regression for 7202 7350
import uuid

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models

from .base import BaseModel


class BinaryData(models.Model):
    data = models.BinaryField(null=True)


class BooleanData(models.Model):
    data = models.BooleanField(default=False, null=True)


class CharData(models.Model):
    data = models.CharField(max_length=30, null=True)


class DateData(models.Model):
    data = models.DateField(null=True)


class DateTimeData(models.Model):
    data = models.DateTimeField(null=True)


class DecimalData(models.Model):
    data = models.DecimalField(null=True, decimal_places=3, max_digits=5)


class EmailData(models.Model):
    data = models.EmailField(null=True)


class FileData(models.Model):
    data = models.FileField(null=True)


class FilePathData(models.Model):
    data = models.FilePathField(null=True)


class FloatData(models.Model):
    data = models.FloatField(null=True)


class IntegerData(models.Model):
    data = models.IntegerField(null=True)


class BigIntegerData(models.Model):
    data = models.BigIntegerField(null=True)






class GenericIPAddressData(models.Model):
    data = models.GenericIPAddressField(null=True)


class PositiveBigIntegerData(models.Model):
    data = models.PositiveBigIntegerField(null=True)


class PositiveIntegerData(models.Model):
    data = models.PositiveIntegerField(null=True)


class PositiveSmallIntegerData(models.Model):
    data = models.PositiveSmallIntegerField(null=True)


class SlugData(models.Model):
    data = models.SlugField(null=True)


class SmallData(models.Model):
    data = models.SmallIntegerField(null=True)


class TextData(models.Model):
    data = models.TextField(null=True)


class TimeData(models.Model):
    data = models.TimeField(null=True)


class Tag(models.Model):
    

    data = models.SlugField()
    content_type = models.ForeignKey(ContentType, models.CASCADE)
    object_id = models.PositiveIntegerField()

    content_object = GenericForeignKey()

    class Meta:
        ordering = ["data"]


class GenericData(models.Model):
    data = models.CharField(max_length=30)

    tags = GenericRelation(Tag)







class Anchor(models.Model):
    

    data = models.CharField(max_length=30)

    class Meta:
        ordering = ("id",)


class UniqueAnchor(models.Model):
    

    data = models.CharField(unique=True, max_length=30)


class FKData(models.Model):
    data = models.ForeignKey(Anchor, models.SET_NULL, null=True)


class M2MData(models.Model):
    data = models.ManyToManyField(Anchor)


class O2OData(models.Model):
    
    data = models.OneToOneField(Anchor, models.CASCADE, primary_key=True)


class FKSelfData(models.Model):
    data = models.ForeignKey("self", models.CASCADE, null=True)


class M2MSelfData(models.Model):
    data = models.ManyToManyField("self", symmetrical=False)


class FKDataToField(models.Model):
    data = models.ForeignKey(UniqueAnchor, models.SET_NULL, null=True, to_field="data")


class FKDataToO2O(models.Model):
    data = models.ForeignKey(O2OData, models.SET_NULL, null=True)


class M2MIntermediateData(models.Model):
    data = models.ManyToManyField(Anchor, through="Intermediate")


class Intermediate(models.Model):
    left = models.ForeignKey(M2MIntermediateData, models.CASCADE)
    right = models.ForeignKey(Anchor, models.CASCADE)
    extra = models.CharField(max_length=30, blank=True, default="doesn't matter")










class BooleanPKData(models.Model):
    data = models.BooleanField(primary_key=True, default=False)


class CharPKData(models.Model):
    data = models.CharField(max_length=30, primary_key=True)


class DatePKData(models.Model):
    data = models.DateField(primary_key=True)


class DateTimePKData(models.Model):
    data = models.DateTimeField(primary_key=True)


class DecimalPKData(models.Model):
    data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5)


class EmailPKData(models.Model):
    data = models.EmailField(primary_key=True)






class FilePathPKData(models.Model):
    data = models.FilePathField(primary_key=True)


class FloatPKData(models.Model):
    data = models.FloatField(primary_key=True)


class IntegerPKData(models.Model):
    data = models.IntegerField(primary_key=True)






class GenericIPAddressPKData(models.Model):
    data = models.GenericIPAddressField(primary_key=True)


class PositiveIntegerPKData(models.Model):
    data = models.PositiveIntegerField(primary_key=True)


class PositiveSmallIntegerPKData(models.Model):
    data = models.PositiveSmallIntegerField(primary_key=True)


class SlugPKData(models.Model):
    data = models.SlugField(primary_key=True)


class SmallPKData(models.Model):
    data = models.SmallIntegerField(primary_key=True)









class UUIDData(models.Model):
    data = models.UUIDField(primary_key=True)


class UUIDDefaultData(models.Model):
    data = models.UUIDField(primary_key=True, default=uuid.uuid4)


class FKToUUID(models.Model):
    data = models.ForeignKey(UUIDData, models.CASCADE)






class AutoNowDateTimeData(models.Model):
    data = models.DateTimeField(null=True, auto_now=True)


class ModifyingSaveData(models.Model):
    data = models.IntegerField(null=True)

    def save(self, *args, **kwargs):
        
        self.data = 666
        super().save(*args, **kwargs)






class AbstractBaseModel(models.Model):
    parent_data = models.IntegerField()

    class Meta:
        abstract = True


class InheritAbstractModel(AbstractBaseModel):
    child_data = models.IntegerField()


class InheritBaseModel(BaseModel):
    child_data = models.IntegerField()


class ExplicitInheritBaseModel(BaseModel):
    parent = models.OneToOneField(BaseModel, models.CASCADE, parent_link=True)
    child_data = models.IntegerField()


class LengthModel(models.Model):
    data = models.IntegerField()

    def __len__(self):
        return self.data