

_V                 @   s  d  d l  m Z d  d l Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l m Z m  Z  m! Z! d  d l" m# Z# d  d l$ m% Z% d  d l& m' Z' d  d l( m) Z) m* Z* e+   Z, e-   Z. d Z/ d4 Z0 Gd, d-   d- e+  Z1 d. d/   Z2 d0 d1   Z3 e  Gd2 d3   d3 e+   Z4 d S)5    )unicode_literalsN)bisect)OrderedDictdefaultdict)chain)apps)settings)FieldDoesNotExist)connections)	AutoField)OrderWrt)ManyToManyField)six)ImmutableList
OrderedSet)RemovedInDjango110Warning)
force_textpython_2_unicode_compatible
smart_text)cached_property)	lru_cache)camel_case_to_spaces)overridestring_concatzyThe return type of '%s' should never be mutated. If you want to manipulate this list for your own use, make a copy first.verbose_nameverbose_name_pluraldb_tableorderingunique_togetherpermissionsget_latest_byorder_with_respect_to	app_labeldb_tablespaceabstractmanagedproxy	swappableauto_createdindex_togetherr   default_permissionsselect_on_savedefault_related_namerequired_db_featuresrequired_db_vendorc               @   s(   e  Z d  Z d d   Z d d   Z d S)raise_deprecationc             C   s   | |  _  d  S)N)suggested_alternative)selfr0    r2   :/tmp/pip-build-ghmbqnp_/Django/django/db/models/options.py__init__-   s    zraise_deprecation.__init__c                s      f d d   } | S)Nc                 s3   t  j d   j  j f t d d   |  |   S)NzZ'%s is an unofficial API that has been deprecated. You may be able to replace it with '%s'
stacklevel   )warningswarn__name__r0   r   )argskwargs)fnr1   r2   r3   wrapper1   s    
z+raise_deprecation.__call__.<locals>.wrapperr2   )r1   r<   r=   r2   )r<   r1   r3   __call__0   s    
zraise_deprecation.__call__N)r9   
__module____qualname__r4   r>   r2   r2   r2   r3   r/   ,   s   r/   c             C   s   yv |  s f  St  |  t t f  s+ t  n  t t |    } t  | t t f  s^ |  f }  n  t d d   |  D  SWn t k
 r |  SYn Xd S)z
    option_together can be either a tuple of tuples, or a single
    tuple of two strings. Normalize it to a tuple of tuples, so that
    calling code can uniformly expect that.
    c             s   s   |  ] } t  |  Vq d  S)N)tuple).0Zotr2   r2   r3   	<genexpr>M   s    z%normalize_together.<locals>.<genexpr>N)
isinstancerA   list	TypeErrornextiter)Zoption_togetherZfirst_elementr2   r2   r3   normalize_together>   s    	rI   c             C   s   t  | d t |  S)Nwarning)r   IMMUTABLE_WARNING)namedatar2   r2   r3   make_immutable_fields_listT   s    rN   c               @   sj  e  Z d  Z dh Z di Z d	 d
 d  Z e d d	  d d    Z e d d	  d d    Z e	 d d    Z
 e	 d d    Z e	 d d    Z e	 d d    Z e	 d d    Z e	 d d    Z d d   Z d d    Z d! d" d#  Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z e	 d. d/    Z e	 d0 d1    Z e d2 d3    Z e d4 d5    Z e d6 d7    Z e d8 d9  d: d;    Z e d8 d9  d< d=    Z  e d> d?    Z! e d@ dA    Z" e d8 d9  dB dC    Z# e dD dE    Z$ e dF dG    Z% d	 dH dI  Z& e d8 dJ  dK dL    Z' e d8 d9  dM dN    Z( e d8 d9  d! d! d! dO dP   Z) e d8 d9  d! d! d! dQ dR   Z* e d8 d9  d! dS dT   Z+ e d8 d9  dU dV    Z, dW dX   Z- dY dZ   Z. d[ d\   Z/ d] d^   Z0 e d_ d`    Z1 da da db dc  Z2 da d! dd de  Z3 da da da d! d	 df dg  Z4 d	 S)jOptionsfieldsmany_to_manyconcrete_fieldslocal_concrete_fields_forward_fields_maprelated_objects
fields_map_relation_treeNc             C   si  i  |  _  g  |  _ g  |  _ g  |  _ g  |  _ d  |  _ d  |  _ d  |  _ d |  _ g  |  _	 d |  _
 g  |  _ g  |  _ d |  _ d |  _ g  |  _ d  |  _ | |  _ d  |  _ d  |  _ t j |  _ g  |  _ d  |  _ | |  _ d  |  _ d |  _ d  |  _ d |  _ d |  _ d |  _ d  |  _  d  |  _! d  |  _" t#   |  _$ d |  _% g  |  _& g  |  _' t( |  _( d  |  _) d  S)N FaddchangedeleteT)zaddrZ   zdelete)*_get_fields_cacheproxied_childrenlocal_fieldslocal_many_to_manyvirtual_fields
model_namer   r   r   r   _ordering_clashr   r)   r+   r*   r   object_namer"   r    r!   r   ZDEFAULT_TABLESPACEr#   r-   r.   metapkZhas_auto_fieldZ
auto_fieldr$   r%   r&   proxy_for_modelconcrete_modelr'   r   parentsr(   managersZrelated_fkey_lookupsr   r,   )r1   rd   r"   r2   r2   r3   r4   ^   sN    																																				zOptions.__init__maxsizec             C   s1   | j  j j } | |  j  k r' d  } n  | | f S)N)model_metarg   )r1   linkrk   r2   r2   r3   
_map_model   s    	zOptions._map_modelc             C   s\   | j  p | j } | j j j } | |  j k r: d  } n  | j oI | j } | | | | f S)N)r(   concreterk   rl   rg   is_relationrQ   )r1   rm   directrk   Zm2mr2   r2   r3   _map_model_details   s    	zOptions._map_model_detailsc             C   s   d |  j  |  j f S)Nz%s.%s)r"   rc   )r1   r2   r2   r3   label   s    zOptions.labelc             C   s   d |  j  |  j f S)Nz%s.%s)r"   ra   )r1   r2   r2   r3   label_lower   s    zOptions.label_lowerc             C   s   |  j  j j |  j  S)N)r   Zapp_configsgetr"   )r1   r2   r2   r3   
app_config   s    zOptions.app_configc             C   s   |  j  d  k	 S)N)rv   )r1   r2   r2   r3   	installed   s    zOptions.installedc             C   s   d d   |  j  D S)Nc             S   s1   g  |  ]' \ } } } | r | | j  | f  q Sr2   )rL   )rB   counterinstancer$   r2   r2   r3   
<listcomp>   s   	 z-Options.abstract_managers.<locals>.<listcomp>)ri   )r1   r2   r2   r3   abstract_managers   s    	zOptions.abstract_managersc             C   s   d d   |  j  D S)Nc             S   s1   g  |  ]' \ } } } | s | | j  | f  q Sr2   )rL   )rB   rx   ry   r$   r2   r2   r3   rz      s   	 z-Options.concrete_managers.<locals>.<listcomp>)ri   )r1   r2   r2   r3   concrete_managers   s    	zOptions.concrete_managersc             C   sE  d d l  m } d d l m } |  | _ | |  _ | j |  _ |  j j   |  _	 t
 |  j  |  _ i  |  _ |  j r|  j j j   } x- |  j j D] } | j d  r | | =q q Wx t D] } | | k rt |  | | j |   t |  |  |  j | <q t |  j |  r t |  | t |  j |   t |  |  |  j | <q q Wt |  j  |  _ t |  j  |  _ |  j d  k rt |  j d  |  _ n  t |  j o|  j  |  _ | i  k rt d d j  | j!      qn t |  j d  |  _ |  ` |  j" sAd |  j# |  j	 f |  _" | |  j" | j$ j%    |  _" n  d  S)	Nr   )
connection)truncate_name_sz)'class Meta' got invalid attribute(s): %s,z%s_%s)&	django.dbr}   Zdjango.db.backends.utilsr~   rl   rk   r9   rc   lowerra   r   r   Zoriginal_attrsrd   __dict__copy
startswithDEFAULT_NAMESsetattrpopgetattrhasattrrI   r   r)   r   r   boolr   r!   rb   rF   joinkeysr   r"   opsZmax_name_length)r1   clsrL   r}   r~   Z
meta_attrs	attr_namer2   r2   r3   contribute_to_class   s@    				%	zOptions.contribute_to_classc                sf  |  j  r |  j   y2 t  f d d   |  j d d  D  |  _  Wn+ t k
 rq t d |  j  f   Yn Xd |  _ t d d   | j j	 D  s | j
 d t    q n	 d  |  _  |  j d  k rb|  j r4t t j |  j       f d d	   |  j	 D } | r| d
   n  d   _ |  j    qbt d d d d d d  } | j
 d |  n  d  S)Nc             3   s3   |  ]) } | j    k s' | j   k r | Vq d  S)N)rL   attname)rB   f)queryr2   r3   rC     s    z#Options._prepare.<locals>.<genexpr>reverseFz%s has no field named %r_orderc             s   s   |  ] } t  | t  Vq d  S)N)rD   r   )rB   fieldr2   r2   r3   rC     s    c                s(   g  |  ] } | j    j  k r |  q Sr2   )rL   )rB   Zfld)r   r2   r3   rz   $  s   	 z$Options._prepare.<locals>.<listcomp>r   Tr   ZIDprimary_keyr(   id)r   )r!   rG   _get_fieldsStopIterationr	   rc   r   anyrl   r^   Zadd_to_classr   re   rh   r   
itervaluesr   setup_pkr   )r1   rk   Zalready_createdZautor2   )r   r   r3   _prepare	  s,    		/					zOptions._prepareFc             C   s   | r |  j  j |  n` | j rM | j rM |  j j t |  j |  |  n, |  j j t |  j |  |  |  j |  | j r t	 | j
 d  r | j
 j r y | j
 j j j d d  Wn t k
 r Yn X|  j   n |  j d d  d  S)Nrk   forwardFr   )r`   appendrp   rQ   r_   insertr   r^   r   r   remote_fieldrk   rl   _expire_cacheAttributeError)r1   r   Zvirtualr2   r2   r3   	add_field.  s    "
'zOptions.add_fieldc             C   s,   |  j  r( | j r( | |  _  d | _ n  d  S)NF)re   r   	serialize)r1   r   r2   r2   r3   r   L  s    	zOptions.setup_pkc             C   s+   | j  j |  _ | |  _ | j  j |  _ d S)zd
        Does the internal setup so that the current model is a proxy for
        "target".
        N)rl   re   rf   r   )r1   targetr2   r2   r3   setup_proxyQ  s    	zOptions.setup_proxyc             C   s   d |  j  S)Nz<Options for %s>)rc   )r1   r2   r2   r3   __repr__Z  s    zOptions.__repr__c             C   s    d t  |  j  t  |  j  f S)Nz%s.%s)r   r"   ra   )r1   r2   r2   r3   __str__]  s    zOptions.__str__c                s   |  j  s |  j s |  j r  d St   t j  r? t     n  |  j rX |  j   j k S|  j	 r t
   f d d   |  j	 D  Sd S)z
        Return True if the model can/should be migrated on the `connection`.
        `connection` can be either a real connection or a connection alias.
        Fc             3   s$   |  ] } t    j | d   Vq d S)FN)r   features)rB   Zfeat)r}   r2   r3   rC   l  s   z&Options.can_migrate.<locals>.<genexpr>T)r&   swappedr%   rD   r   string_typesr
   r.   vendorr-   all)r1   r}   r2   )r}   r3   can_migrate`  s    		zOptions.can_migratec          	   C   s$   t  d   t |  j  SWd QXd S)z
        There are a few places where the untranslated verbose name is needed
        (so that we get the same value regardless of currently active
        locale).
        N)r   r   r   )r1   r2   r2   r3   verbose_name_rawp  s    zOptions.verbose_name_rawc             C   s   |  j  r t t |  j  d  } | r y | j d  \ } } Wn t k
 rU | SYn Xd | | j   f |  j k r| | Sq n  d S)a!  
        Has this model been swapped out for another? If so, return the model
        name of the replacement; otherwise, return None.

        For historical reasons, model name lookups using get_model() are
        case insensitive, so we make sure we are case insensitive here.
        N.z%s.%s)r'   r   r   split
ValueErrorr   rt   )r1   Zswapped_forZswapped_labelZswapped_objectr2   r2   r3   r   z  s    			
zOptions.swappedc                sV   d d    d d    d d     t  d     f d d   |  j d d	  D  S)
a2  
        Returns a list of all forward fields on the model and its parents,
        excluding ManyToManyFields.

        Private API intended only to be used by Django itself; get_fields()
        combined with filtering of field properties is the public API for
        obtaining this field list.
        c             S   s   |  j  o |  j S)N)rp   rQ   )r   r2   r2   r3   <lambda>  s    z Options.fields.<locals>.<lambda>c             S   s   |  j  o |  j S)N)rp   Zone_to_many)r   r2   r2   r3   r     s    c             S   s0   |  j  o. |  j o. t |  j d  o- |  j j S)Nrk   )rp   many_to_oner   r   rk   )r   r2   r2   r3   r     s    rP   c             3   s9   |  ]/ }  |  r  |  r   |  r | Vq d  S)Nr2   )rB   r   )is_not_a_generic_foreign_keyis_not_a_generic_relationis_not_an_m2m_fieldr2   r3   rC     s    z!Options.fields.<locals>.<genexpr>r   F)rN   r   )r1   r2   )r   r   r   r3   rP     s    zOptions.fieldsc             C   s   t  d d d   |  j D  S)a  
        Returns a list of all concrete fields on the model and its parents.

        Private API intended only to be used by Django itself; get_fields()
        combined with filtering of field properties is the public API for
        obtaining this field list.
        rR   c             s   s   |  ] } | j  r | Vq d  S)N)ro   )rB   r   r2   r2   r3   rC     s    z*Options.concrete_fields.<locals>.<genexpr>)rN   rP   )r1   r2   r2   r3   rR     s    	zOptions.concrete_fieldsc             C   s   t  d d d   |  j D  S)z
        Returns a list of all concrete fields on the model.

        Private API intended only to be used by Django itself; get_fields()
        combined with filtering of field properties is the public API for
        obtaining this field list.
        rS   c             s   s   |  ] } | j  r | Vq d  S)N)ro   )rB   r   r2   r2   r3   rC     s    z0Options.local_concrete_fields.<locals>.<genexpr>)rN   r^   )r1   r2   r2   r3   rS     s    	zOptions.local_concrete_fieldsr0   zget_fields()c                s     f d d     j    D S)Nc                s   g  |  ] }   j  |   q Sr2   )rn   )rB   r   )r1   r2   r3   rz     s   	 z1Options.get_fields_with_model.<locals>.<listcomp>)
get_fields)r1   r2   )r1   r3   get_fields_with_model  s    zOptions.get_fields_with_modelc                s     f d d     j  D S)Nc                s   g  |  ] }   j  |   q Sr2   )rn   )rB   r   )r1   r2   r3   rz     s   	 z:Options.get_concrete_fields_with_model.<locals>.<listcomp>)rR   )r1   r2   )r1   r3   get_concrete_fields_with_model  s    z&Options.get_concrete_fields_with_modelc             C   s&   t  d d d   |  j d d  D  S)a  
        Returns a list of all many to many fields on the model and its parents.

        Private API intended only to be used by Django itself; get_fields()
        combined with filtering of field properties is the public API for
        obtaining this list.
        rQ   c             s   s'   |  ] } | j  r | j r | Vq d  S)N)rp   rQ   )rB   r   r2   r2   r3   rC     s    z'Options.many_to_many.<locals>.<genexpr>r   F)rN   r   )r1   r2   r2   r3   rQ     s    	zOptions.many_to_manyc             C   s8   |  j  d d d d d d  } t d d d   | D  S)	ax  
        Returns all related objects pointing to the current model. The related
        objects can come from a one-to-one, one-to-many, or many-to-many field
        relation type.

        Private API intended only to be used by Django itself; get_fields()
        combined with filtering of field properties is the public API for
        obtaining this field list.
        r   Fr   Tinclude_hiddenrU   c             s   s+   |  ]! } | j  s | j j r | Vq d  S)N)hiddenr   rQ   )rB   objr2   r2   r3   rC     s    z*Options.related_objects.<locals>.<genexpr>)r   rN   )r1   Zall_related_fieldsr2   r2   r3   rU     s    zOptions.related_objectsc                s     f d d     j  D S)Nc                s   g  |  ] }   j  |   q Sr2   )rn   )rB   r   )r1   r2   r3   rz     s   	 z.Options.get_m2m_with_model.<locals>.<listcomp>)rQ   )r1   r2   )r1   r3   get_m2m_with_model  s    zOptions.get_m2m_with_modelc             C   s`   i  } |  j  d d  } xA | D]9 } | | | j <y | | | j <Wq t k
 rW Yq Xq W| S)Nr   F)r   rL   r   r   )r1   resrP   r   r2   r2   r3   rT     s    	zOptions._forward_fields_mapc             C   sf   i  } |  j  d d d d  } xA | D]9 } | | | j <y | | | j <Wq% t k
 r] Yq% Xq% W| S)Nr   Fr   T)r   rL   r   r   )r1   r   rP   r   r2   r2   r3   rV     s    	zOptions.fields_mapc             C   s  | d k	 } | r% t  j d t  n  yF |  j | } | d k rf | j rf t d |  j | f   n  | SWn: t k
 r |  j j	 s t d |  j | f   n  Yn Xy1 | r t d |  j | f   n  |  j
 | SWn+ t k
 rt d |  j | f   Yn Xd S)af  
        Returns a field instance given a field name. The field can be either a
        forward or reverse field, unless many_to_many is specified; if it is,
        only forward fields will be returned.

        The many_to_many argument exists for backwards compatibility reasons;
        it has been deprecated and will be removed in Django 1.10.
        NzeThe 'many_to_many' argument on get_field() is deprecated; use a filter on field.many_to_many instead.Fz%s has no field named %rz%s has no field named %r. The app cache isn't ready yet, so if this is an auto-created related field, it won't be available yet.)r7   r8   r   rT   rQ   r	   rc   KeyErrorr   Zmodels_readyrV   )r1   
field_namerQ   Zm2m_in_kwargsr   r2   r2   r3   	get_field  s,    	
zOptions.get_fieldzget_field()c             C   s   |  j  |  j |   S)N)rr   r   )r1   rL   r2   r2   r3   get_field_by_nameH  s    zOptions.get_field_by_namec             C   s   t    } |  j   } x | D] } | j rI | j rI | j d  k rI q n  | j |  j k ry | j j j |  j k ry q n  | j | j	  t
 | d  r | j | j  q q Wt |  S)Nr   )setr   rp   r   related_modelrk   rl   rg   rY   rL   r   r   rE   )r1   namesrP   r   r2   r2   r3   get_all_field_namesL  s    	!zOptions.get_all_field_namesc          	      s   | d k r d n t  }  j d d d d d | d    } d d   | D } | r t j  f d	 d    j j j D  }   f d
 d   | D } t | |  } n  t |  S)NFTr   r   include_parentsr   c             s   s'   |  ] } t  | j t  s | Vq d  S)N)rD   r   r   )rB   r   r2   r2   r3   rC   i  s    z2Options.get_all_related_objects.<locals>.<genexpr>c             3   s$   |  ] } |   k	 r | j  Vq d  S)N)rW   )rB   c)r1   r2   r3   rC   k  s   c             3   s4   |  ]* }   s% | j  j j  j   r | j  Vq d  S)N)r   r   Z	is_hidden)rB   r   )r   r2   r3   rC   n  s    )PROXY_PARENTSr   r   from_iterablerg   rl   r]   rE   )r1   
local_onlyr   include_proxy_eqr   rP   childrenZ	relationsr2   )r   r1   r3   get_all_related_objects_  s    		zOptions.get_all_related_objectsc                s/     f d d     j  d | d | d |  D S)Nc                s   g  |  ] }   j  |   q Sr2   )rn   )rB   r   )r1   r2   r3   rz   w  s   	 z>Options.get_all_related_objects_with_model.<locals>.<listcomp>r   r   r   )r   )r1   r   r   r   r2   )r1   r3   "get_all_related_objects_with_models  s    z*Options.get_all_related_objects_with_modelc          	   C   sM   | d k	 r d n t  } |  j d d d d d | d d  } d d   | D S)	NTr   Fr   r   r   c             S   s(   g  |  ] } t  | j t  r |  q Sr2   )rD   r   r   )rB   r   r2   r2   r3   rz     s   	 z@Options.get_all_related_many_to_many_objects.<locals>.<listcomp>)r   r   )r1   r   r   rP   r2   r2   r3   $get_all_related_many_to_many_objects~  s
    	z,Options.get_all_related_many_to_many_objectsc                s5     j  d d d d d d  }   f d d   | D S)Nr   Fr   Tr   c                s1   g  |  ]' } t  | j t  r   j |   q Sr2   )rD   r   r   rn   )rB   r   )r1   r2   r3   rz     s   	 zBOptions.get_all_related_m2m_objects_with_model.<locals>.<listcomp>)r   )r1   rP   r2   )r1   r3   &get_all_related_m2m_objects_with_model  s    z.Options.get_all_related_m2m_objects_with_modelc             C   sg   |  j  s g  S| |  j  k r# | g Sx= |  j  D]2 } | j j |  } | r- | j d |  | Sq- Wg  S)z
        Return a list of parent classes leading to `model` (ordered from
        closest to most distant ancestor). This has to handle the case where
        `model` is a grandparent or even more distant relation.
        r   )rh   rl   get_base_chainr   )r1   rk   parentr   r2   r2   r3   r     s    	zOptions.get_base_chainc             C   sT   t  |  j  } x8 |  j D]- } x$ | j j   D] } | j |  q/ Wq Wt |  S)z
        Returns all the ancestors of this model as a list ordered by MRO.
        Useful for determining if something is an ancestor, regardless of lineage.
        )r   rh   rl   get_parent_listrY   rE   )r1   resultr   ancestorr2   r2   r3   r     s
    zOptions.get_parent_listc             C   s[   | |  j  k r |  j  | Sx: |  j  D]/ } | j j |  } | r$ |  j  | pR | Sq$ Wd S)a^  
        Returns the field on the current model which points to the given
        "ancestor". This is possible an indirect link (a pointer to a parent
        model, which points, eventually, to the ancestor). Used when
        constructing table joins for model inheritance.

        Returns None if the model isn't an ancestor of this one.
        N)rh   rl   get_ancestor_link)r1   r   r   parent_linkr2   r2   r3   r     s    	zOptions.get_ancestor_linkc             C   s   t  t  } |  j j d d  } x | D] } | j j r@ q( n  d d   | j j d d d d  D } xC | D]; } t | j j	 t
 j  so | | j j	 j j |  qo qo Wq( Wx+ | D]# } | | j } | | j j d <q W|  j j d t  S)	a%  
        This method is used by each model to find its reverse objects. As this
        method is very expensive and is accessed frequently (it looks up every
        field in a model, in every app), it is computed on first access and then
        is set as a property on every model.
        Zinclude_auto_createdTc             s   s-   |  ]# } | j  r | j d  k	 r | Vq d  S)N)rp   r   )rB   r   r2   r2   r3   rC     s    z<Options._populate_directed_relation_graph.<locals>.<genexpr>r   Fr   rW   )r   rE   r   Z
get_modelsrl   r$   r   rD   r   rk   r   r   r   r   ru   EMPTY_RELATION_TREE)r1   Zrelated_objects_graphZ
all_modelsrk   Zfields_with_relationsr   rU   r2   r2   r3   !_populate_directed_relation_graph  s    (%z)Options._populate_directed_relation_graphc             C   s
   |  j    S)N)r   )r1   r2   r2   r3   rW     s    zOptions._relation_treeTc             C   s   g  } | r | j  |  j  n  | rB |  j rB | j  |  j  n  x4 | D], } y t |  |  WqI t k
 rt YqI XqI Wi  |  _ d  S)N)extendFORWARD_PROPERTIESr$   REVERSE_PROPERTIESdelattrr   r\   )r1   r   r   Zproperties_to_expire	cache_keyr2   r2   r3   r     s    	zOptions._expire_cachec             C   s+   | d k r t  } n  |  j d | d |  S)a  
        Returns a list of fields associated to the model. By default, includes
        forward and reverse fields, fields derived from inheritance, but not
        hidden fields. The returned fields can be changed using the parameters:

        - include_parents: include fields derived from inheritance
        - include_hidden:  include fields that have a related_name that
                           starts with a "+"
        Fr   r   )r   r   )r1   r   r   r2   r2   r3   r     s    
	zOptions.get_fieldsc             C   s  | d d t  f k r+ t d | f   n  d } | d k rO t   } d } n  | j |  j  | | | | | f } y |  j | SWn t k
 r Yn Xg  } | d k	 r]x |  j D] }	 |	 | k r q n  |	 j j	 |  j	 k r | t  k r q n  x` |	 j j
 d | d | d | d | d	 |  D]1 }
 t |
 d
  rE|
 j rEq!n  | j |
  q!Wq Wn  | r|  j } x7 | D], } | s| j j rs| j | j  qsqsWn  | r| j d d   t |  j |  j  D  | r| j d d   |  j D  qn  t d |  } | |  j | <| S)a  
        Internal helper function to return fields of the model.
        * If forward=True, then fields defined on this model are returned.
        * If reverse=True, then relations pointing to this model are returned.
        * If include_hidden=True, then fields with is_hidden=True are returned.
        * The include_parents argument toggles if fields from parent models
          should be included. It has three values: True, False, and
          PROXY_PARENTS. When set to PROXY_PARENTS, the call will return all
          fields defined for the current model or any of its parents in the
          parent chain to the model's concrete model.
        TFz(Invalid argument for include_parents: %sNr   r   r   r   seen_modelsr   c             s   s   |  ] } | Vq d  S)Nr2   )rB   r   r2   r2   r3   rC   G  s    z&Options._get_fields.<locals>.<genexpr>c             s   s   |  ] } | Vq d  S)Nr2   )rB   r   r2   r2   r3   rC   P  s    zget_fields())r   rF   r   rY   rk   r\   r   rh   rl   rg   r   r   r   r   rW   r   r   r   r   r^   r_   r`   rN   )r1   r   r   r   r   r   Ztopmost_callr   rP   r   r   Z
all_fieldsr   r2   r2   r3   r     sP    			#zOptions._get_fields)zfieldszmany_to_manyzconcrete_fieldszlocal_concrete_fieldsz_forward_fields_map)zrelated_objectsz
fields_mapz_relation_tree)5r9   r?   r@   r   r   r4   r   rn   rr   propertyrs   rt   rv   rw   r{   r|   r   r   r   r   r   r   r   r   r   r   r   rP   rR   rS   r/   r   r   rQ   rU   r   rT   rV   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   r2   r2   r2   r3   rO   X   sj    <7%	
3	#rO   )zverbose_namezverbose_name_pluralzdb_tablezorderingzunique_togetherzpermissionszget_latest_byzorder_with_respect_toz	app_labelzdb_tablespacezabstractzmanagedzproxyz	swappablezauto_createdzindex_togetherzappszdefault_permissionszselect_on_savezdefault_related_namezrequired_db_featureszrequired_db_vendor)5
__future__r   r7   r   collectionsr   r   	itertoolsr   Zdjango.appsr   Zdjango.confr   Zdjango.core.exceptionsr	   r   r
   Zdjango.db.models.fieldsr   Zdjango.db.models.fields.proxyr   Zdjango.db.models.fields.relatedr   Zdjango.utilsr   Zdjango.utils.datastructuresr   r   Zdjango.utils.deprecationr   Zdjango.utils.encodingr   r   r   Zdjango.utils.functionalr   Zdjango.utils.lru_cacher   Zdjango.utils.textr   Zdjango.utils.translationr   r   objectr   rA   r   rK   r   r/   rI   rN   rO   r2   r2   r2   r3   <module>   sD   		      