<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class R ( models . Model ) : <EOL> is_default = models . BooleanField ( default = False ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT:%s>" % self . pk <EOL> def get_default_r ( ) : <EOL> return R . objects . get_or_create ( is_default = True ) [ <NUM_LIT:0> ] . pk <EOL> class S ( models . Model ) : <EOL> r = models . ForeignKey ( R , models . CASCADE ) <EOL> class T ( models . Model ) : <EOL> s = models . ForeignKey ( S , models . CASCADE ) <EOL> class U ( models . Model ) : <EOL> t = models . ForeignKey ( T , models . CASCADE ) <EOL> class RChild ( R ) : <EOL> pass <EOL> class A ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> auto = models . ForeignKey ( R , models . CASCADE , related_name = "<STR_LIT>" ) <EOL> auto_nullable = models . ForeignKey ( R , models . CASCADE , null = True , related_name = '<STR_LIT>' ) <EOL> setvalue = models . ForeignKey ( R , models . SET ( get_default_r ) , related_name = '<STR_LIT>' ) <EOL> setnull = models . ForeignKey ( R , models . SET_NULL , null = True , related_name = '<STR_LIT>' ) <EOL> setdefault = models . ForeignKey ( R , models . SET_DEFAULT , default = get_default_r , related_name = '<STR_LIT>' ) <EOL> setdefault_none = models . ForeignKey ( <EOL> R , models . SET_DEFAULT , <EOL> default = None , null = True , related_name = '<STR_LIT>' , <EOL> ) <EOL> cascade = models . ForeignKey ( R , models . CASCADE , related_name = '<STR_LIT>' ) <EOL> cascade_nullable = models . ForeignKey ( R , models . CASCADE , null = True , related_name = '<STR_LIT>' ) <EOL> protect = models . ForeignKey ( R , models . PROTECT , null = True ) <EOL> donothing = models . ForeignKey ( R , models . DO_NOTHING , null = True , related_name = '<STR_LIT>' ) <EOL> child = models . ForeignKey ( RChild , models . CASCADE , related_name = "<STR_LIT>" ) <EOL> child_setnull = models . ForeignKey ( RChild , models . SET_NULL , null = True , related_name = "<STR_LIT>" ) <EOL> o2o_setnull = models . ForeignKey ( R , models . SET_NULL , null = True , related_name = "<STR_LIT>" ) <EOL> def create_a ( name ) : <EOL> a = A ( name = name ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> r = R . objects . create ( ) <EOL> setattr ( a , name , r ) <EOL> a . child = RChild . objects . create ( ) <EOL> a . child_setnull = RChild . objects . create ( ) <EOL> a . save ( ) <EOL> return a <EOL> class M ( models . Model ) : <EOL> m2m = models . ManyToManyField ( R , related_name = "<STR_LIT>" ) <EOL> m2m_through = models . ManyToManyField ( R , through = "<STR_LIT>" , related_name = "<STR_LIT>" ) <EOL> m2m_through_null = models . ManyToManyField ( R , through = "<STR_LIT>" , related_name = "<STR_LIT>" ) <EOL> class MR ( models . Model ) : <EOL> m = models . ForeignKey ( M , models . CASCADE ) <EOL> r = models . ForeignKey ( R , models . CASCADE ) <EOL> class MRNull ( models . Model ) : <EOL> m = models . ForeignKey ( M , models . CASCADE ) <EOL> r = models . ForeignKey ( R , models . SET_NULL , null = True ) <EOL> class Avatar ( models . Model ) : <EOL> desc = models . TextField ( null = True ) <EOL> class AvatarProxy ( Avatar ) : <EOL> class Meta : <EOL> proxy = True <EOL> class User ( models . Model ) : <EOL> avatar = models . ForeignKey ( Avatar , models . CASCADE , null = True ) <EOL> class HiddenUser ( models . Model ) : <EOL> r = models . ForeignKey ( R , models . CASCADE , related_name = "<STR_LIT:+>" ) <EOL> class HiddenUserProfile ( models . Model ) : <EOL> user = models . ForeignKey ( HiddenUser , models . CASCADE ) <EOL> class M2MTo ( models . Model ) : <EOL> pass <EOL> class M2MFrom ( models . Model ) : <EOL> m2m = models . ManyToManyField ( M2MTo ) <EOL> class Parent ( models . Model ) : <EOL> pass <EOL> class Child ( Parent ) : <EOL> pass <EOL> class Base ( models . Model ) : <EOL> pass <EOL> class RelToBase ( models . Model ) : <EOL> base = models . ForeignKey ( Base , models . DO_NOTHING ) </s>
