Commit d862fae5 authored by Daniel Pyrathon's avatar Daniel Pyrathon Committed by Tim Graham
Browse files

Refs #12663 -- Added tests for methods in db.models.options.

Thanks Russell Keith-Magee and Tim Graham for reviews.
parent 01399fa0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -517,6 +517,7 @@ answer newbie questions, and generally made Django that much better:
    Matthias Pronk <django@masida.nl>
    Jyrki Pulliainen <jyrki.pulliainen@gmail.com>
    Thejaswi Puthraya <thejaswi.puthraya@gmail.com>
    Daniel Pyrathon <pirosb3@gmail.com>
    Johann Queuniet <johann.queuniet@adh.naellia.eu>
    Ram Rachum <ram@rachum.com>
    Jan Rademaker
+0 −0

Empty file added.

+120 −0
Original line number Diff line number Diff line
from django.db import models

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


class Relation(models.Model):
    pass


class AbstractPerson(models.Model):
    # DATA fields
    data_abstract = models.CharField(max_length=10)
    fk_abstract = models.ForeignKey(Relation, related_name='fk_abstract_rel')

    # M2M fields
    m2m_abstract = models.ManyToManyField(Relation, related_name='m2m_abstract_rel')
    friends_abstract = models.ManyToManyField('self', related_name='friends_abstract', symmetrical=True)
    following_abstract = models.ManyToManyField('self', related_name='followers_abstract', symmetrical=False)

    # VIRTUAL fields
    data_not_concrete_abstract = models.ForeignObject(
        Relation,
        from_fields=['abstract_non_concrete_id'],
        to_fields=['id'],
        related_name='fo_abstract_rel',
    )

    # GFK fields
    content_type_abstract = models.ForeignKey(ContentType, related_name='+')
    object_id_abstract = models.PositiveIntegerField()
    content_object_abstract = GenericForeignKey('content_type_abstract', 'object_id_abstract')

    # GR fields
    generic_relation_abstract = GenericRelation(Relation)

    class Meta:
        abstract = True


class BasePerson(AbstractPerson):
    # DATA fields
    data_base = models.CharField(max_length=10)
    fk_base = models.ForeignKey(Relation, related_name='fk_base_rel')

    # M2M fields
    m2m_base = models.ManyToManyField(Relation, related_name='m2m_base_rel')
    friends_base = models.ManyToManyField('self', related_name='friends_base', symmetrical=True)
    following_base = models.ManyToManyField('self', related_name='followers_base', symmetrical=False)

    # VIRTUAL fields
    data_not_concrete_base = models.ForeignObject(
        Relation,
        from_fields=['base_non_concrete_id'],
        to_fields=['id'],
        related_name='fo_base_rel',
    )

    # GFK fields
    content_type_base = models.ForeignKey(ContentType, related_name='+')
    object_id_base = models.PositiveIntegerField()
    content_object_base = GenericForeignKey('content_type_base', 'object_id_base')

    # GR fields
    generic_relation_base = GenericRelation(Relation)


class Person(BasePerson):
    # DATA fields
    data_inherited = models.CharField(max_length=10)
    fk_inherited = models.ForeignKey(Relation, related_name='fk_concrete_rel')

    # M2M Fields
    m2m_inherited = models.ManyToManyField(Relation, related_name='m2m_concrete_rel')
    friends_inherited = models.ManyToManyField('self', related_name='friends_concrete', symmetrical=True)
    following_inherited = models.ManyToManyField('self', related_name='followers_concrete', symmetrical=False)

    # VIRTUAL fields
    data_not_concrete_inherited = models.ForeignObject(
        Relation,
        from_fields=['model_non_concrete_id'],
        to_fields=['id'],
        related_name='fo_concrete_rel',
    )

    # GFK fields
    content_type_concrete = models.ForeignKey(ContentType, related_name='+')
    object_id_concrete = models.PositiveIntegerField()
    content_object_concrete = GenericForeignKey('content_type_concrete', 'object_id_concrete')

    # GR fields
    generic_relation_concrete = GenericRelation(Relation)


class ProxyPerson(Person):
    class Meta:
        proxy = True


class Relating(models.Model):

    # ForeignKey to BasePerson
    baseperson = models.ForeignKey(BasePerson, related_name='relating_baseperson')
    baseperson_hidden = models.ForeignKey(BasePerson, related_name='+')

    # ForeignKey to Person
    person = models.ForeignKey(Person, related_name='relating_person')
    person_hidden = models.ForeignKey(Person, related_name='+')

    # ForeignKey to ProxyPerson
    proxyperson = models.ForeignKey(ProxyPerson, related_name='relating_proxyperson')
    proxyperson_hidden = models.ForeignKey(ProxyPerson, related_name='+')

    # ManyToManyField to BasePerson
    basepeople = models.ManyToManyField(BasePerson, related_name='relating_basepeople')
    basepeople_hidden = models.ManyToManyField(BasePerson, related_name='+')

    # ManyToManyField to Person
    people = models.ManyToManyField(Person, related_name='relating_people')
    people_hidden = models.ManyToManyField(Person, related_name='+')
+656 −0

File added.

Preview size limit exceeded, changes collapsed.