
    h*                       S SK r S SKrS SKrS SK Jr  S SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJr  S SKJr  S SKJr  S SKJ r   S SK!J"r"  S SK#J$r%  SSK&J'r'  SSK(J)r)  SSK*J+r+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2J3r3J4r4J5r5J6r6J7r7J8r8  SSK9J:r:J;r;J<r<J=r=  Sr>S r?S r@ " S S\)\'5      rA " S S\A5      rB\BR                  \55        \BR                  \25        \BR                  \75        \BR                  \35        \BR                  \45        \BR                  \85        \BR                  \65         " S S\B5      rD " S  S!\D5      rES" rF " S# S$\A5      rGg)%    N)partial)forms)apps)SettingsReferencesettings)checks
exceptions)
connectionrouter)utils)Q)
LOOKUP_SEP)CASCADESET_DEFAULTSET_NULL)PathInfomake_model_tuple)RemovedInDjango60Warning)cached_property)gettext_lazy   )Field)FieldCacheMixin)ForeignKeyDeferredAttributeForwardManyToOneDescriptorForwardOneToOneDescriptorManyToManyDescriptorReverseManyToOneDescriptorReverseOneToOneDescriptor)RelatedExactRelatedGreaterThanRelatedGreaterThanOrEqual	RelatedInRelatedIsNullRelatedLessThanRelatedLessThanOrEqual)ForeignObjectRelManyToManyRelManyToOneRelOneToOneRelselfc                     U[         :X  a  U n[        U[        5      (       a#  SU;  a  U R                  R                  < SU< 3nU$ )a  
Transform relation into a model or fully-qualified model string of the form
"app_label.ModelName", relative to scope_model.

The relation argument can be:
  * RECURSIVE_RELATIONSHIP_CONSTANT, i.e. the string "self", in which case
    the model argument will be returned.
  * A bare model name without an app_label, in which case scope_model's
    app_label will be prepended.
  * An "app_label.ModelName" string.
  * A model class, which will be returned unchanged.
.)RECURSIVE_RELATIONSHIP_CONSTANT
isinstancestr_meta	app_label)scope_modelrelations     Q/var/www/html/env/lib/python3.13/site-packages/django/db/models/fields/related.pyresolve_relationr7   -   sD     22 (C  h"-"3"3"="=xHHO    c                     U/U Vs/ s H  n[        X5      PM     sn-   nS U 5       nUR                  R                  nUR                  " [	        U 40 UD6/UQ76 $ s  snf )a  
Schedule `function` to be called once `model` and all `related_models`
have been imported and registered with the app registry. `function` will
be called with the newly-loaded model classes as its positional arguments,
plus any optional keyword arguments.

The `model` argument must be a model class. Each subsequent positional
argument is another model, or a reference to another model - see
`resolve_relation()` for the various forms these may take. Any relative
references will be resolved relative to `model`.

This is a convenience wrapper for `Apps.lazy_model_operation` - the app
registry model used is the one found in `model._meta.apps`.
c              3   8   #    U  H  n[        U5      v   M     g 7fNr   ).0ms     r6   	<genexpr>)lazy_related_operation.<locals>.<genexpr>V   s     6v!"1%%v   )r7   r2   r   lazy_model_operationr   )functionmodelrelated_modelskwargsrelmodels
model_keysr   s           r6   lazy_related_operationrI   F   sd     WO(4OOF6v6J;;D$$WX%@%@N:NN Ps   Ac                     ^  \ rS rSrSrSrSrSrSr   SU 4S jjr	\
S 5       rU 4S jrS rS rS	 rS
 rS rS rSU 4S jjrU 4S jrS rS r\S 5       rS rS rS rU 4S jrS r\S 5       r\
S 5       rSr U =r!$ )RelatedField[   z3Base class that all relational fields inherit from.Fc                 J   > Xl         X l        X0l        [        TU ]  " S0 UD6  g N )_related_name_related_query_name_limit_choices_tosuper__init__)r,   related_namerelated_query_namelimit_choices_torE   	__class__s        r6   rT   RelatedField.__init__d   s'     *#5 !1"6"r8   c                 X    [         R                  " 5         U R                  R                  $ r;   )r   check_models_readyremote_fieldrC   r,   s    r6   related_modelRelatedField.related_modelp   s"     	!  &&&r8   c                    > / [         TU ]  " S0 UD6QU R                  5       QU R                  5       QU R	                  5       QU R                  5       QU R                  5       Q$ rN   )rS   check_check_related_name_is_valid"_check_related_query_name_is_valid_check_relation_model_exists#_check_referencing_to_swapped_model_check_clashesr,   rE   rX   s     r6   ra   RelatedField.checkv   s~    
W]$V$
..0
 446
 ..0	

 557
   "
 	
r8   c                    SS K nU R                  R                  nUc  / $ UR                  U5      (       + =(       a    UR	                  5       nU(       dv  UR                  S5      (       d`  [        R                  " SU R                  R                  < SU R                  R                  R                  < SU R                  < 3SU SS9/$ / $ )	Nr   +z
The name 'z$' is invalid related_name for field r.   z@Related name must be a valid Python identifier or end with a '+'zfields.E306hintobjid)keywordr\   rU   	iskeywordisidentifierendswithr   ErrorrC   r2   object_namename)r,   ro   rU   is_valid_ids       r6   rb   )RelatedField._check_related_name_is_valid   s    ((55I!!,//OL4M4M4O 	 |44S99 ))66

((44			 $   	r8   c           	      \   U R                   R                  (       a  / $ U R                  5       n/ nUR                  S5      (       a)  UR	                  [
        R                  " SU-  SU SS95        [        U;   a3  UR	                  [
        R                  " SU< S[        < S3SU S	S95        U$ )
N_z8Reverse query name '%s' must not end with an underscore.zKAdd or change a related_name or related_query_name argument for this field.zfields.E308rk   zReverse query name 'z' must not contain ''.zfields.E309)r\   hiddenrV   rr   appendr   rs   r   )r,   rel_query_nameerrorss      r6   rc   /RelatedField._check_related_query_name_is_valid   s    ##I002""3''MMN$%3 $	 'MM%z33 $	 r8   c                     U R                   R                  U R                  R                  R	                  5       ;  n[        U R                   R                  [        5      nU(       a  U R                   R                  O)U R                   R                  R                  R                  nU(       aP  U(       d/  U R                   R                  R                  R                  (       d  [        R                  " SU-  U SS9/$ / $ )NzXField defines a relation with model '%s', which is either not installed, or is abstract.zfields.E300rm   rn   )r\   rC   optsr   
get_modelsr0   r1   r2   rt   swappedr   rs   )r,   rel_is_missingrel_is_string
model_names       r6   rd   )RelatedField._check_relation_model_exists   s    **00		8Q8Q8SS"4#4#4#:#:C@  ##""((..:: 	
 !2!2!8!8!>!>!F!F 57AB$	  	r8   c                 
   U R                   R                  U R                  R                  R	                  5       ;  a  [        U R                   R                  [        5      (       d  U R                   R                  R                  R                  (       an  [        R                  " SU R                   R                  R                  R                  -  SU R                   R                  R                  R                  -  U SS9/$ / $ )NzIField defines a relation with the model '%s', which has been swapped out.z.Update the relation to point at 'settings.%s'.zfields.E301rk   )r\   rC   r   r   r   r0   r1   r2   r   r   rs   label	swappabler]   s    r6   re   0RelatedField._check_referencing_to_swapped_model   s    ##499>>+D+D+FFt0066<<!!''--55 (*.*;*;*A*A*G*G*M*MNI''--33==>$	 	 	r8   c                   ^  SSK Jn  / nT R                  R                  n[	        T R
                  R                  U5      (       d  / $ T R
                  R                  R                  nT R
                  R                  nT R
                  R                  nT R                  5       nUR                  < ST R                  < 3nUR                  UR                  -   n	U	 H  n
U(       dq  U
R                  U:X  aa  UR                   SU
R                   3nUR                  [        R                  " SUR                    SU SU SU S3	SU< S	U< S3T S
S95        U
R                  U:X  d  M  UR                   SU
R                   3nUR                  [        R                  " SU< SU< S3SU< S	U< S3T SS95        M     U 4S jUR"                   5       n	U	 GH  n
U(       d  U
R                  U:X  a  U
R$                  R                  R                   SU
R&                  R                   3nUR                  [        R                  " SUR                    SU SU SU S3	SU< SU< S3T SS95        U
R                  U:X  d  M  U
R$                  R                  R                   SU
R&                  R                   3nUR                  [        R                  " SU< SU< S3SU< SU< S3T SS95        GM      U$ )z.Check accessor and reverse query name clashes.r   )	ModelBaser.   zReverse accessor 'z' for 'z' clashes with field name 'rz   zRename field 'zF', or add/change a related_name argument to the definition for field 'zfields.E302rk   zReverse query name for 'zfields.E303c              3   H   >#    U  H  oR                   TLd  M  Uv   M     g 7fr;   field)r<   rr,   s     r6   r>   .RelatedField._check_clashes.<locals>.<genexpr>/  s     X(@1GGSWDWQQ(@s   "	"z%' clashes with reverse accessor for 'z=Add or change a related_name argument to the definition for '' or 'zfields.E304z'' clashes with reverse query name for 'zfields.E305)django.db.models.baser   rC   r2   r0   r\   r{   accessor_namerV   r   ru   fieldsmany_to_manyr|   r   rs   rt   related_objectsr^   r   )r,   r   r~   r   rel_optsrel_is_hiddenrel_namer}   
field_namepotential_clashesclash_field
clash_names   `           r6   rf   RelatedField._check_clashes   s   3zz $++119==I $$**00 ))00$$22002 $

DII6

 %OOh.C.CC,K [%5%5%A (/q1A1A0BC
LL,X-A-A,B!H: N  *| ,&<r+ &z	3
 !( >1 (/q1A1A0BC
LL%z3 &z	3
 !(
) -J Y(@(@X,K [%>%>(%J"0066<<=Q{?P?P?U?U>VW  LL,X-A-A,B!H: N  *| ,&<r+ &z	3
 !( ((N:"0066<<=Q{?P?P?U?U>VW  LL'1:? &z	3
 !(
1 -L r8   c                     g r;   rO   r,   r
   s     r6   db_typeRelatedField.db_typeX       r8   c                 V  > [         TU ]  " X4SU0UD6  UR                  U l        UR                  R                  (       Gdh  U R
                  R                  (       a  U R
                  R                  nOU R                  R                  nU(       au  UUR                  R                  5       UR                  R                  R                  5       UR                  R                  R                  5       S.-  nXPR
                  l        U R
                  R                  (       af  U R
                  R                  UR                  R                  5       UR                  R                  R                  5       S.-  nX`R
                  l        S n[        XqU R
                  R                  U S9  g g )Nprivate_only)classr   r3   )r   r3   c                 F    XR                   l        UR                  X5        g r;   )r\   rC   do_related_class)rC   relatedr   s      r6   resolve_related_class?RelatedField.contribute_to_class.<locals>.resolve_related_classv  s    +2""(&&w6r8   r   )rS   contribute_to_classr2   r   abstractr\   rU   default_related_name__name__lowerr   r3   rV   rI   rC   )	r,   clsru   r   rE   rU   rV   r   rX   s	           r6   r    RelatedField.contribute_to_class]  sH   #CSLSFSII	yy!!!  --#00==#yy== \\//1"%))"6"6"<"<">!$!4!4!:!:!<! 
 2>!!.  33%)%6%6%I%I \\//1!$!4!4!:!:!<M &" 8J!!47 #%D,=,=,C,C41 "r8   c                    > [         TU ]  5       u  pp4U R                  (       a  U R                  US'   U R                  b  U R                  US'   U R                  b  U R                  US'   XX44$ )NrW   rU   rV   )rS   deconstructrR   rP   rQ   r,   ru   pathargsrE   rX   s        r6   r   RelatedField.deconstruct~  ss    #(7#6#8 D!!)-)?)?F%&)%)%7%7F>"##/+/+C+CF'(4''r8   c           	          U R                    VVs0 s H6  u  p#U R                  < SUR                  < 3[        XR                  5      _M8     snn$ s  snnf )a  
Return the keyword arguments that when supplied to
self.model.object.filter(), would select all instances related through
this field to the remote obj. This is used to build the querysets
returned by related descriptors. obj is an instance of
self.related_field.model.
__)related_fieldsru   getattrattname)r,   rm   ry   rh_fields       r6   get_forward_related_filter'RelatedField.get_forward_related_filter  sN      $22
2 		8==173@P@P3QQ2
 	
 
s   =Ac                 8   [         R                  " U R                   VVs/ s H&  u  p#UR                  [	        XR                  5      4PM(     snn5      nU R                  U5      n[        U[        5      (       a  U[        S0 UD6-  $ U(       a  XE-  $ U$ s  snnf )z
Complement to get_forward_related_filter(). Return the keyword
arguments that when passed to self.related_field.model.object.filter()
select all instances of self.related_field.model related through
this field to obj. obj is an instance of self.model.
rO   )r   creater   r   r   get_extra_descriptor_filterr0   dict)r,   rm   lh_fieldr   base_qdescriptor_filters         r6   get_reverse_related_filter'RelatedField.get_reverse_related_filter  s      +/*=*=*=&H !!730@0@#AB*=
 !<<SA'..A2 1222--s   -B
c                 &   U R                   (       a  [        U R                  R                  [        5      (       a  U R                  R                  nO*U R                  R                  R
                  R                  n[        R                  " U5      $ g)zw
Get the setting that this is powered from for swapping, or None
if it's not swapped in / marked with swappable=False.
N)	r   r0   r\   rC   r1   r2   r   r   get_swappable_settings_name)r,   	to_strings     r6   swappable_settingRelatedField.swappable_setting  sf     >>$++11377 --33	 --3399??	33I>>r8   c                    U R                   =(       db    U R                  R                  R                  R                  S-   U R                  R                  R                  R
                  R                   -   U l         U R                  c/  U R                  R                  R                  R                  U l        U R                  R                  5         g )Nry   )ru   r\   rC   r2   r   pkverbose_nameset_field_namer]   s    r6   set_attributes_from_rel$RelatedField.set_attributes_from_rel  s    II 
##))44%%++..334 		
 $ $ 1 1 7 7 = = J JD((*r8   c                 Z    U R                  5         U R                  XR                  5        g r;   )r   contribute_to_related_classr\   )r,   otherr   s      r6   r   RelatedField.do_related_class  s"    $$&((0A0ABr8   c                     [        U R                  R                  5      (       a  U R                  R                  5       $ U R                  R                  $ )z}
Return ``limit_choices_to`` for this model field.

If it is a callable, it will be invoked and the result will be
returned.
)callabler\   rW   r]   s    r6   get_limit_choices_to!RelatedField.get_limit_choices_to  sB     D%%6677$$5577  111r8   c                    > 0 n[        U R                  S5      (       a)  U R                  R                  nUR                  SU05        UR                  U5        [        TU ]  " S0 UD6$ )z
Pass ``limit_choices_to`` to the field being constructed.

Only passes it if there is a type that supports related fields.
This is a similar strategy used to pass the ``queryset`` to the field
being constructed.
get_related_fieldrW   rO   )hasattrr\   rW   updaterS   	formfield)r,   rE   defaultsrW   rX   s       r6   r   RelatedField.formfield  sj     4$$&9::  $00AAOO&(8
 	w ,8,,r8   c                     U R                   R                  =(       d3    U R                   R                  =(       d    U R                  R                  $ )z]
Define the name that can be used to identify this related object in a
table-spanning query.
)r\   rV   rU   r   r   r]   s    r6   rV   RelatedField.related_query_name  s>     00 $  --$yy##	
r8   c                     U R                   S   R                  n[        U5      S:  a  [        R                  " S5      eUS   $ )zw
When filtering against this relation, return the field on the remote
model against which the filtering should happen.
r   zSThe relation has multiple target fields, but only single target field was asked forr   )
path_infostarget_fieldslenr	   
FieldError)r,   r   s     r6   target_fieldRelatedField.target_field  sJ     +99}!''   Qr8   c                     U R                   $ r;   ru   r]   s    r6   
cache_nameRelatedField.cache_name   s    yyr8   )rR   rP   rQ   ru   r   r   )NNNF)"r   
__module____qualname____firstlineno____doc__one_to_many
one_to_oner   many_to_onerT   r   r^   ra   rb   rc   rd   re   rf   r   r   r   r   r   propertyr   r   r   r   r   rV   r   r   __static_attributes____classcell__rX   s   @r6   rK   rK   [   s    = KJLK 	
# ' '

8B*$rh
B(
(  +C	2-,	
      r8   rK   c                     ^  \ rS rSrSrSrSrSrSrSr	\
r\r\r      S"U 4S jjrU 4S jrU 4S jrS rS	 rU 4S
 jrS r\S 5       r\S 5       r\S 5       r\S 5       rS rS r\S 5       rU 4S jr S#S jr!S r"S#S jr#S r$S r%S r&S$S jr'\S 5       r(S$S jr)\S 5       r*\+\,RZ                  S 5       5       r.S#U 4S jjr/S  r0S!r1U =r2$ )%ForeignObjecti  zK
Abstraction of the ForeignKey relation to support multi-column relations.
FTc           
         > Uc  U R                  U UUUUU	US9n[        TU ]  " SUUUUS.UD6  X0l        X@l        Xl        g )NrU   rV   rW   parent_link	on_delete)rF   rU   rV   rW   rO   )	rel_classrS   rT   from_fields	to_fieldsr   )r,   tor  r  r	  rF   rU   rV   rW   r  r   rE   rX   s               r6   rT   ForeignObject.__init__  sn     ;..)#5!1'# ! C 	 	
%1-		

 	
 '""r8   c                    > [         TU ]  5       nUR                  R                  SS 5        UR                  R                  SS 5        U$ )Nr   reverse_path_infos)rS   __copy____dict__pop)r,   rm   rX   s     r6   r  ForeignObject.__copy__:  s>    g t,-t4
r8   c                 h   > / [         TU ]  " S0 UD6QU R                  5       QU R                  5       Q$ rN   )rS   ra   _check_to_fields_exist_check_unique_targetrg   s     r6   ra   ForeignObject.checkA  sE    
W]$V$
((*
 &&(
 	
r8   c                    [        U R                  R                  [        5      (       a  / $ / nU R                   H<  nU(       d  M   U R                  R                  R
                  R                  U5        M>     U$ ! [        R                   aZ    UR                  [        R                  " SU< SU R                  R                  R
                  R                  < S3U SS95         M  f = f)NzThe to_field 'z&' doesn't exist on the related model 'rz   zfields.E312r   )r0   r\   rC   r1   r	  r2   	get_fieldr	   FieldDoesNotExistr|   r   rs   r   )r,   r~   to_fields      r6   r  $ForeignObject._check_to_fields_existH  s    d''--s33IHx%%++11;;HE '  "33 	MM  ():):)@)@)F)F)L)LN !%,	s   /A<<A*C*)C*c                   ^ [        U R                  R                  [        5      nU(       d  U R                  (       d  / $  U R
                    U R
                  (       d  / $ [        S U R
                   5       5      nU(       d  U R
                   Vs1 s H  o3R                  iM     snmU R                  R                  R                  n[        U4S jUR                   5       5      =(       d    [        U4S jUR                   5       5      nU(       d  [        U R
                  5      S:  aa  SR                  S U R
                   5       5      nU R                  R                  R                  n[         R"                  " SU SU S	3S
U SS9/$ U R
                  S   R                  nU R                  R                  R                  n[         R"                  " SU SU S3SU SS9/$ / $ ! [        R                   a    / s $ f = fs  snf )Nc              3   8   #    U  H  oR                   v   M     g 7fr;   )uniquer<   	rel_fields     r6   r>   5ForeignObject._check_unique_target.<locals>.<genexpr>k  s      $
.I.Ir@   c              3   @   >#    U  H  n[        U5      T:*  v   M     g 7fr;   )	frozenset)r<   utforeign_fieldss     r6   r>   r   q  s      (:UB	"/:Us   c              3   T   >#    U  H  n[        UR                  5      T:*  v   M     g 7fr;   )r"  r   )r<   ucr$  s     r6   r>   r   s  s&      >B "))$6>s   %(r   , c              3   B   #    U  H  nS UR                    S 3v   M     g7f)'Nr   r  s     r6   r>   r   z  s"      .;Via	'q);Vs   zNo subset of the fields z on model 'z' is unique.zMark a single field as unique=True or add a set of fields to a unique constraint (via unique_together or a UniqueConstraint (without condition) in the model Meta.constraints).zfields.E310rk   r   r)  r.   z;' must be unique because it is referenced by a foreign key.zjAdd unique=True to this field or add a UniqueConstraint (without condition) in the model Meta.constraints.zfields.E311)r0   r\   rC   r1   requires_unique_targetforeign_related_fieldsr	   r  anyru   r2   unique_togethertotal_unique_constraintsr   joinr   r   rs   )	r,   r   has_unique_constraintfremote_optsfield_combinationr   r   r$  s	           @r6   r  "ForeignObject._check_unique_target^  s   "4#4#4#:#:C@ ; ;I	'' **I # $
.2.I.I$
 !
 %.2.I.IJ.Iff.IJN++1177K$' (:E:U:U( % % %>>  " %4../!3$(II .;?;V;V. %! "..44==
LL23D2E F&<|57
 !(  "88;@@
!..44==
LLJ<q 57 70 !(
  	o ++ 	I	 Ks   G) H)HHc                   > [         TU ]  5       u  pp4U R                  R                  US'   U R                  US'   U R
                  US'   U R                  R                  (       a  U R                  R                  US'   [        U R                  R                  [        5      (       a  SU R                  R                  ;   aB  U R                  R                  R                  S5      u  pVU< SUR                  5       < 3US'   OUU R                  R                  R                  5       US'   O-U R                  R                  R                  R                  US'   U R                  nUbZ  [        US   S5      (       a4  US   R                   U:w  a!  [#        SUS   R                   < S	U< S
35      e[%        US   U5      US'   XX44$ )Nr  r  r	  r  r.   r
  setting_namezeCannot deconstruct a ForeignKey pointing to a model that is swapped in place of more than one model ( and ))rS   r   r\   r  r  r	  r  r0   rC   r1   splitr   r2   label_lowerr   r   r6  
ValueErrorr   	r,   ru   r   r   rE   r3   r   r   rX   s	           r6   r   ForeignObject.deconstruct  s   #(7#6#8 D"//99{ $ 0 0}"nn{(($($5$5$A$AF=!d''--s33d''---(,(9(9(?(?(E(Ec(J%	*3Z5E5E5GHt#0066<<>t,,2288DDF4L !22(vd|^44$<,,0AA$ "$<446GI  -t!F4L 4''r8   c                    U R                   (       a,  [        U R                   5      [        U R                  5      :w  a  [        S5      e[	        U R
                  R                  [        5      (       a"  [        SU R
                  R                  -  5      e/ n[        U R                   U R                  5       H  u  p#U[        :X  a  U OU R                  R                  U5      nUc*  U R
                  R                  R                  R                  O.U R
                  R                  R                  R                  U5      nUR                  XE45        M     U$ )NzBForeign Object from and to fields must be the same non-zero lengthz#Related model %r cannot be resolved)r  r   r	  r;  r0   r\   rC   r1   zipr/   r   r  r2   r   r|   )r,   r   from_field_nameto_field_name
from_fieldr  s         r6   resolve_related_fields$ForeignObject.resolve_related_fields  s$   3t'7'7#8C<O#OT  d''--s3358I8I8O8OO  .1$2B2BDNN.S*O #&EE YY((9  !( !!''--00&&,,22<<]K 
 !!:"89 /T r8   c                 "    U R                  5       $ r;   )rC  r]   s    r6   r   ForeignObject.related_fields  s    **,,r8   c                 R    U R                    VVs/ s H  u  pX!4PM
     snn$ s  snnf r;   )r   )r,   	lhs_field	rhs_fields      r6   reverse_related_fields$ForeignObject.reverse_related_fields  s(    CGCVCVWCV+?9&CVWWWs   #c                 :    [        S U R                   5       5      $ )Nc              3   *   #    U  H	  u  pUv   M     g 7fr;   rO   r<   rH  rI  s      r6   r>   5ForeignObject.local_related_fields.<locals>.<genexpr>  s     O;N#79Y;Ns   tupler   r]   s    r6   local_related_fields"ForeignObject.local_related_fields  s    O4;N;NOOOr8   c                 :    [        S U R                   5       5      $ )Nc              3   <   #    U  H  u  pU(       d  M  Uv   M     g 7fr;   rO   rN  s      r6   r>   7ForeignObject.foreign_related_fields.<locals>.<genexpr>  s      
2E.)II2Es   	rP  r]   s    r6   r+  $ForeignObject.foreign_related_fields  s"     
262E2E
 
 	
r8   c                 8    U R                  XR                  5      $ r;   )get_instance_value_for_fieldsrR  r,   instances     r6   get_local_related_value%ForeignObject.get_local_related_value  s    11(<U<UVVr8   c                 8    U R                  XR                  5      $ r;   )rY  r+  rZ  s     r6   get_foreign_related_value'ForeignObject.get_foreign_related_value  s    11(<W<WXXr8   c                    / nU R                   nU H  nUR                  (       au  UR                  UR                  5      nU(       a6  UR                  (       d%  UR                  R                   R                  (       a  UR                  U R                  5        M  UR                  [        XR                  5      5        M     [        U5      $ r;   )
r2   primary_keyget_ancestor_linkrC   r   r|   r   r   r   rQ  )r[  r   retr   r   possible_parent_links         r6   rY  +ForeignObject.get_instance_value_for_fields  s    ~~E   '+'='=ekk'J$,+77+1177@@JJx{{+JJwx78  Szr8   c                 ,   > [         TU ]  5       u  pUS 4$ r;   )rS   get_attname_column)r,   r   columnrX   s      r6   rh   ForeignObject.get_attname_column  s    '46}r8   c                     [         R                  " S[        5        U(       a  U R                  OU R                  n[        S U 5       5      $ )NzTForeignObject.get_joining_columns() is deprecated. Use get_joining_fields() instead.c              3   V   #    U  H  u  pUR                   UR                   4v   M!     g 7fr;   )ri  rN  s      r6   r>   4ForeignObject.get_joining_columns.<locals>.<genexpr>  s'      
MS5IYYy//0Vs   '))warningswarnr   rJ  r   rQ  )r,   reverse_joinsources      r6   get_joining_columns!ForeignObject.get_joining_columns	  sG    ,$	

 1=,,$BUBU 
MS
 
 	
r8   c                 V    [         R                  " S[        5        U R                  SS9$ )NzdForeignObject.get_reverse_joining_columns() is deprecated. Use get_reverse_joining_fields() instead.Trp  )rn  ro  r   rr  r]   s    r6   get_reverse_joining_columns)ForeignObject.get_reverse_joining_columns  s,    4$	

 ''T'::r8   c                 Z    [        U(       a  U R                  5      $ U R                  5      $ r;   )rQ  rJ  r   )r,   rp  s     r6   get_joining_fields ForeignObject.get_joining_fields  s-    +7D''
 	
=A=P=P
 	
r8   c                      U R                  SS9$ )NTru  )ry  r]   s    r6   get_reverse_joining_fields(ForeignObject.get_reverse_joining_fields!  s    &&D&99r8   c                     0 $ )a  
Return an extra filter condition for related object fetching when
user does 'instance.fieldname', that is the extra filter is used in
the descriptor of the field.

The filter should be either a dict usable in .filter(**kwargs) call or
a Q-object. The condition will be ANDed together with the relation's
joining columns.

A parallel method is get_extra_restriction() which is used in
JOIN and subquery conditions.
rO   rZ  s     r6   r   )ForeignObject.get_extra_descriptor_filter$  s	     	r8   c                     g)a  
Return a pair condition used for joining and subquery pushdown. The
condition is something that responds to as_sql(compiler, connection)
method.

Note that currently referring both the 'alias' and 'related_alias'
will not work in some conditions, like subquery pushdown.

A parallel method is get_extra_descriptor_filter() which is used in
instance.fieldname related object fetching.
NrO   )r,   aliasrelated_aliass      r6   get_extra_restriction#ForeignObject.get_extra_restriction3  s     r8   c           
          U R                   R                  R                  nU R                  R                  n[        UUU R                  U SSUS9/$ )z.Get path from this field to the related model.FT	from_optsto_optsr   
join_fieldm2mdirectfiltered_relation)r\   rC   r2   r   r+  r,   r  r   r  s       r6   get_path_infoForeignObject.get_path_infoA  sU      &&,,JJ$$	#"99"3

 
	
r8   c                 "    U R                  5       $ r;   r  r]   s    r6   r   ForeignObject.path_infosQ      !!##r8   c           
          U R                   R                  nU R                  R                   R                  n[        UUUR                  4U R                  U R
                  (       + SUS9/$ )z6Get path from the related model to this field's model.Fr  )rC   r2   r\   r   r   r  r  s       r6   get_reverse_path_info#ForeignObject.get_reverse_path_infoU  sa    zz%%++11	##wwj,,O"3

 
	
r8   c                 "    U R                  5       $ r;   r  r]   s    r6   r   ForeignObject.reverse_path_infose      ))++r8   c                     [         R                  " U 5      nUS UR                  [        5      S-    nU Vs/ s H  o"R                  R                  S0 5      PM      nnU R                  U5      $ s  snf )Nr   class_lookups)inspectgetmroindexr  r  getmerge_dicts)r   basesparentr  s       r6   get_class_lookupsForeignObject.get_class_lookupsi  sg     s#6M2Q67PUVPUf,,_bAPUV}-- Ws   %A.c                 v   > [         TU ]  " X4SU0UD6  [        XR                  U R	                  U 5      5        g )Nr   )rS   r   setattrru   forward_related_accessor_class)r,   r   ru   r   rE   rX   s        r6   r   !ForeignObject.contribute_to_classq  s3    #CSLSFSYY C CD IJr8   c                    U R                   R                  (       d  UR                  R                  R                  (       d  [        UR                  R                  UR                  U R                  U5      5        U R                   R                  (       a:  UR                  R                  R                  U R                   R                  5        g g g g r;   )r\   r{   r^   r2   r   r  concrete_modelr   related_accessor_classrW   related_fkey_lookupsr|   )r,   r   r   s      r6   r   )ForeignObject.contribute_to_related_classu  s       ''0E0E0K0K0S0S		((%%++G4   11		..55%%66 2 1T'r8   )r  r   r	  )NNNNFTr   r;   )3r   r   r   r   r   r   r   r   r   r*  r   r  r   r  r(   r  rT   r  ra   r  r  r   rC  r   r   rJ  rR  r+  r\  r_  staticmethodrY  rh  rr  rv  ry  r|  r   r  r  r   r  r  classmethod	functoolscacher  r   r   r   r   r   s   @r6   r  r    sh   
 LKKJ!7%?" I ##J
,>@!(F0 - - X X P P 
 

WY  &	
;

:
  $ $
  , , __.  .K r8   r  c                   \  ^  \ rS rSrSr\rSrSrSr	Sr
\rSrS\" S5      0r\" S5      r      S$U 4S	 jjrS
 rU 4S jrS rS rU 4S jrS r\S 5       rU 4S jrU 4S jrS rS rU 4S jrS rS%S jr S r!U 4S jr"SS.U 4S jjr#S r$S r%S r&S r'S  r(U 4S! jr)S&U 4S" jjr*S#r+U =r,$ )'
ForeignKeyi  z
Provide a many-to-one relation by adding a column to the local model
to hold the remote value.

By default ForeignKey will target the pk of the remote model but this
behavior can be changed by using the ``to_field`` argument.
FTinvalidz;%(model)s instance with %(field)s %(value)r does not exist.z.Foreign Key (type determined by related field)Nc	                 :  >  UR                   R                    U=(       d=    UR                   R                  =(       a     UR                   R                  R                  n[        U5      (       d  [        S5      eU R                  U UUUUUUUS9U	S'   U	R                  SS5        [        T
U ]<  " UU4UUU[        /U/S.U	D6  Xl        g ! [         aF    [        U[        5      (       d.  [        U R                  R                  < SU< S[        < 35      e Nf = f)	N(z`) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string zon_delete must be callable.r  rF   db_indexT)rU   rV   rW   r  r	  )r2   r   r   ru   AttributeErrorr0   r1   	TypeErrorrX   r   r/   r   r  
setdefaultrS   rT   db_constraint)r,   r
  r  rU   rV   rW   r  r  r  rE   rX   s             r6   rT   ForeignKey.__init__  s    	FHH   EBHHKK$DBHHKK4D4DH	""9::%1-# ' 	
u 	*d+		
 &1-89j		
 		
 +S  
	b#&& //7  '
	s   C
 
ADDc                     U $ r;   rO   )r   r   rE   s      r6   __class_getitem__ForeignKey.__class_getitem__  s    
r8   c                 h   > / [         TU ]  " S0 UD6QU R                  5       QU R                  5       Q$ rN   )rS   ra   _check_on_delete_check_uniquerg   s     r6   ra   ForeignKey.check  sE    
W]$V$
""$
 !
 	
r8   c                    [        U R                  SS 5      nU[        :X  a)  U R                  (       d  [        R
                  " SSU SS9/$ U[        :X  a-  U R                  5       (       d  [        R
                  " SSU SS9/$ / $ )	Nr  z7Field specifies on_delete=SET_NULL, but cannot be null.zBSet null=True argument on the field, or change the on_delete rule.zfields.E320rk   z@Field specifies on_delete=SET_DEFAULT, but has no default value.z2Set a default value, or change the on_delete rule.zfields.E321)r   r\   r   nullr   rs   r   has_default)r,   r  s     r6   r  ForeignKey._check_on_delete  s    D--{DA	 M  $
 
 +%d.>.>.@.@VM$	  Ir8   c                 X    U R                   (       a  [        R                  " SSU SS9/$ / $ )NzQSetting unique=True on a ForeignKey has the same effect as using a OneToOneField.zDForeignKey(unique=True) is usually better served by a OneToOneField.zfields.W342rk   )r  r   Warningr,   rE   s     r6   r  ForeignKey._check_unique  s?     {{ ') $		
 	
r8   c                   > [         TU ]  5       u  pp4US	 US	 U R                  (       a  US	 OSUS'   U R                  SLa  U R                  US'   [	        U R
                  R                  SS 5      nU R
                  R                  (       a_  U(       a?  UR                  (       aG  U R
                  R                  UR                  R                  :w  a  U R
                  R                  US'   XX44$ )	Nr	  r  r  FTr  r2   r  )
rS   r   r  r  r   r\   rC   r   r   ru   )r,   ru   r   r   rE   to_metarX   s         r6   r   ForeignKey.deconstruct  s    #(7#6#8 D;=!==z"!&F:T)&*&8&8F?#$++117DA''

t00;;wzzN!%!2!2!=!=F:4''r8   c                 8    U R                   R                  U5      $ r;   )r   	to_pythonr,   values     r6   r  ForeignKey.to_python+  s      **511r8   c                      U R                   S   $ )Nr   )r+  r]   s    r6   r   ForeignKey.target_field.  s    **1--r8   c           	        > U R                   R                  (       a  g [        TU ]  X5        Uc  g [        R
                  " U R                   R                  US9nU R                   R                  R                  R                  U5      R                  " S0 U R                   R                  U0D6nUR                  U R                  5       5      nUR                  5       (       dd  [        R                  " U R                   S   SU R                   R                  R"                  R$                  UU R                   R                  US.S9eg )N)r[  r  )rC   r   r   r  )codeparamsrO   )r\   r  rS   validater   db_for_readrC   _base_managerusingfilterr   complex_filterr   existsr	   ValidationErrorerror_messagesr2   r   )r,   r  model_instancer  qsrX   s        r6   r  ForeignKey.validate2  s   ((/=""4#4#4#:#:^T$$2288?FF 
  ++U3
 t88:;yy{{,,##I.!..44::GG!..99"		 	 r8   c                   > [         TU ]  5       nU H  u  p#U(       d  M  UR                  U R                  R                  R                  R
                  :w  d  MH  [        R                  " SU R                  R                  R                  < SU R                  < SUR                  < SU R                  R                  R                  R
                  R                  R                  < S3	5      e   U$ )Nr)  r.   z' refers to field 'z' which is not local to model 'rz   )
rS   rC  rC   r\   r2   r  r	   r   r   ru   )r,   r   rB  r  rX   s       r6   rC  !ForeignKey.resolve_related_fieldsJ  s    79$2 JNNd&7&7&=&=&C&C&R&RR ++ 

((..		 ))//55DDJJPP	 	 %3 r8   c                      SU R                   -  $ )Nz%s_idr   r]   s    r6   get_attnameForeignKey.get_attname]  s    ""r8   c                 R    U R                  5       nU R                  =(       d    UnX4$ r;   )r  	db_column)r,   r   ri  s      r6   rh  ForeignKey.get_attname_column`  s&    ""$*7r8   c                    > [         TU ]  5       n[        XR                  R                  5      (       a  [        XR                  R                  5      $ U$ )z6Return the to_field if the default value is an object.)rS   get_defaultr0   r\   rC   r   r   r   )r,   field_defaultrX   s     r6   r  ForeignKey.get_defaulte  sD    +-m%6%6%<%<===*;*;*C*CDDr8   c                     Ub<  US:X  a7  U R                   R                  (       a  UR                  R                  (       a  g U R                   R	                  XS9$ )N r
   )r   empty_strings_allowedfeatures!interprets_empty_strings_as_nullsget_db_prep_save)r,   r  r
   s      r6   r  ForeignKey.get_db_prep_savel  sK    =RK%%;;&&HH $$55e5SSr8   c                 :    U R                   R                  XU5      $ r;   )r   get_db_prep_value)r,   r  r
   prepareds       r6   r  ForeignKey.get_db_prep_valuex  s      225hOOr8   c                 8    U R                   R                  U5      $ r;   )r   get_prep_valuer  s     r6   r  ForeignKey.get_prep_value{  s      //66r8   c                    > [         TU ]  X5        U R                  R                  c0  UR                  R
                  R                  U R                  l        g g r;   )rS   r   r\   r   r2   r   ru   )r,   r   r   rX   s      r6   r   &ForeignKey.contribute_to_related_class~  sC    +C9''/+.99<<+<+<D( 0r8   r  c                  > [        U R                  R                  [        5      (       a2  [	        SU R
                  < SU R                  R                  < S35      e[        TU ]  " S0 [        R                  U R                  R                  R                  R                  U5      U R                  R                  S.UESU R                  0ED6$ )NzCannot create form field for z  yet, because its related model z has not been loaded yet)
form_classquerysetrA  blankrO   )r0   r\   rC   r1   r;  ru   rS   r   r   ModelChoiceField_default_managerr  r   r  )r,   r  rE   rX   s      r6   r   ForeignKey.formfield  s    d''--s33 99d//557 
 w  
#44 --33DDJJ5Q!%!2!2!=!= 	
 
 	
r8   c                     g r;   rO   r   s     r6   db_checkForeignKey.db_check      r8   c                 4    U R                   R                  US9$ Nr  )r   rel_db_typer   s     r6   r   ForeignKey.db_type  s      ,,
,CCr8   c                 4    U R                   R                  US9$ r  )r   cast_db_typer   s     r6   r  ForeignKey.cast_db_type  s      ---DDr8   c                     U R                   R                  U5      nU R                  U5      U R                  U5      UR	                  S5      S.$ )N	collation)typera   r  )r   db_parametersr   r  r  )r,   r
   target_db_parameterss      r6   r  ForeignKey.db_parameters  sI    #00>>zJLL,]]:.-11+>
 	
r8   c                 @    U(       d  [        U[        5      (       a  g U$ r;   )r0   r1   )r,   r  
expressionr
   s       r6   convert_empty_strings ForeignKey.convert_empty_strings  s    :eS11r8   c                 z   > [         TU ]  U5      nUR                  R                  (       a  X R                  /-  nU$ r;   )rS   get_db_convertersr  r  r  )r,   r
   
convertersrX   s      r6   r!  ForeignKey.get_db_converters  s8    W.z:
@@5566Jr8   c                    > UcS  U R                   n[        U[        5      (       a2  UR                   nX L a  [        S5      e[        U[        5      (       a  M2  [        TU ]  X5      $ )NzCannot resolve output_field.)r   r0   r  r;  rS   get_col)r,   r  output_fieldrX   s      r6   r%  ForeignKey.get_col  s^    ,,L\:66+88'$%CDD \:66 wu33r8   )r  )NNNFNTr   r;   )-r   r   r   r   r   r   descriptor_classr   r   r   r   r*   r  r  ry   default_error_messagesdescriptionrT   r  ra   r  r  r   r  r   r   r  rC  r  rh  r  r  r  r  r   r   r  r   r  r  r  r!  r%  r   r   r   s   @r6   r  r    s    3LKKJI!1RS DEK 7+r
4
$((2 . .0&#

TP7=
 "& 
 
"DE

4 4r8   r  c                      ^  \ rS rSrSrSrSrSrSr\	r
\r\r\" S5      rSU 4S jjrU 4S jrU 4S jrS	 rS
 rSrU =r$ )OneToOneFieldi  a  
A OneToOneField is essentially the same as a ForeignKey, with the exception
that it always carries a "unique" constraint with it and the reverse
relation always returns the object pointed to (since there will only ever
be one), rather than returning a list.
FTzOne-to-one relationshipc                 6   > SUS'   [         TU ]  " X4SU0UD6  g )NTr  r  )rS   rT   )r,   r
  r  r  rE   rX   s        r6   rT   OneToOneField.__init__  s$    xDDVDr8   c                 @   > [         TU ]  5       u  pp4SU;   a  US	 XX44$ )Nr  )rS   r   r   s        r6   r   OneToOneField.deconstruct  s0    #(7#6#8 Dvx 4''r8   c                 \   > U R                   R                  (       a  g [        TU ]  " S0 UD6$ rN   )r\   r  rS   r   rg   s     r6   r   OneToOneField.formfield  s(    ((w *6**r8   c                     [        X R                  R                  5      (       a  [        XR                  U5        g [        XR
                  U5        Uc  [        XR                  U5        g g r;   )r0   r\   rC   r  ru   r   r,   r[  datas      r6   save_form_dataOneToOneField.save_form_data  sO    d--3344Hii.HllD1 |))T2 r8   c                     / $ r;   rO   r  s     r6   r  OneToOneField._check_unique  s    	r8   rO   r;   )r   r   r   r   r   r   r   r   r   r    r  r   r  r+   r  ry   r*  rT   r   r   r6  r  r   r   r   s   @r6   r,  r,    sY     LKKJ6%>"I-.KE(+
3 r8   r,  c                 j   SSK Jn  S n[        XR                  R                  5      nUR
                  R                  < SU R                  < 3n[        X1XE5        [        U5      S   nUR
                  R                  nXg:X  a
  SU-  nSU-  n[        SS	U R                  UR
                  5      UUR
                  R                  UR
                  R                  Xv4[        S
5      XvS.-  [        S5      XvS.-  U R                  R
                  R                   S.5      n[        UUR"                  4SUSUR$                  XrR'                  USU-  U R                  U R                  R(                  [*        S9XbR'                  USU-  U R                  U R                  R(                  [*        S905      $ )Nr   )rG   c                     U R                   R                  =(       d    UR                   R                  UR                   l        g r;   )r2   managed)rC   r   throughs      r6   set_managed;create_many_to_many_intermediary_model.<locals>.set_managed  s'     % 3 3 Lw}}7L7Lr8   ry   r   zto_%szfrom_%sMetarO   z%(from)s-%(to)s relationship)fromr
  z%(from)s-%(to)s relationships)db_tableauto_createdr3   db_tablespacer-  r   verbose_name_pluralr   r   z%s+)rU   rD  r  r  )	django.dbrG   r7   r\   rC   r2   rt   ru   rI   r   r   r  _get_m2m_db_tabler3   rD  ry   r   Modelr   r  r  r   )	r   klassrG   r>  to_modelru   r
  from_metas	            r6   &create_many_to_many_intermediary_modelrM    s    M  '9'9'?'?@Hkk--uzz:D;x>	(	#A	&BKK""E	{r\E!
//<!.."[[66 %{<='(#$%D#E'$(KK%%**	
D" 	D%**$$"T\#11#00>>! %  !!"T\#11#00>>! " 	
 r8   c                   4  ^  \ rS rSrSrSrSrSrSr\	r
\" S5      r         S!U 4S jjrU 4S jrS	 rS
 rS"S jrS rU 4S jrS#S jrS"S jr\S 5       rS"S jr\S 5       rS rS rS rU 4S jrS rS rS r S r!SS.U 4S jjr"S r#S r$S r%S r&U =r'$ )$ManyToManyFieldi%  a3  
Provide a many-to-many relation by using an intermediary model that
holds two ForeignKey fields pointed at the two sides of the relation.

Unless a ``through`` model was provided, ManyToManyField will use the
create_many_to_many_intermediary_model factory to automatically generate
the intermediary model.
TFzMany-to-many relationshipNc                   >  UR                     Uc	  U[        :H  nUb  U	b  [        S5      eU R                  U UUUUUUUUS9	US'   SU;   U l
        [        TU ]0  " SUUUS.UD6  Xl        Xl        g ! [         aF    [        U[        5      (       d.  [	        U R
                  R                  < SU< S[        < 35      e Nf = f)	Nr  ze) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string z;Cannot specify a db_table if an intermediary model is used.)rU   rV   rW   symmetricalr=  through_fieldsr  rF   r  )rU   rV   rW   rO   )r2   r  r0   r1   r  rX   r   r/   r;  r  has_null_argrS   rT   rB  r   )r,   r
  rU   rV   rW   rQ  r=  rR  r  rB  r   rE   rX   s               r6   rT   ManyToManyField.__init__9  s    	HH  ??K8#7M  %1-#)' ' 

u #f, 	
%1-	
 		
 !"S  
	b#&& //7  '
	s   A1 1AC Cc                    > / [         TU ]  " S0 UD6QU R                  " S0 UD6QU R                  " S0 UD6QU R                  " S0 UD6QU R
                  " S0 UD6Q$ rN   )rS   ra   r  _check_relationship_model_check_ignored_options_check_table_uniquenessrg   s     r6   ra   ManyToManyField.checkt  s    
W]$V$
)&)
 ++5f5
 ((262	

 ))3F3
 	
r8   c                 V    U R                   (       a  [        R                  " SU SS9/$ / $ )Nz"ManyToManyFields cannot be unique.zfields.E330r   )r  r   rs   r  s     r6   r  ManyToManyField._check_unique}  s/    ;;8$  	r8   c                    / nU R                   (       a&  UR                  " [        R                  " SU SS95        U R                  (       a&  UR                  " [        R                  " SU SS95        U R
                  R                  (       a7  U R                  (       a&  UR                  " [        R                  " SU SS95        U R                  (       a&  UR                  " [        R                  " SU S	S95        U$ )
Nz&null has no effect on ManyToManyField.zfields.W340r   z,ManyToManyField does not support validators.zfields.W341z^related_name has no effect on ManyToManyField with a symmetrical relationship, e.g. to "self".zfields.W345z,db_comment has no effect on ManyToManyField.zfields.W346)	rS  r|   r   r  _validatorsr\   rQ  rP   
db_comment)r,   rE   rn  s      r6   rW  &ManyToManyField._check_ignored_options  s    OO<$ OOB$ ((T-?-?OOG$	 ??OOB$ r8   c                   ^^ [        U R                  R                  S5      (       aP  U R                  R                  R                  R                  < SU R                  R                  R
                  < 3nOU R                  R                  n/ nU R                  R                  U R                  R                  R                  SS9;  a*  UR                  [        R                  " SU-  U SS95        GOTc   S5       e[        TU R                  R                  5      mTR                  R                  n[        T[         5      (       a  TnOTR                  R                  nU R                  R                  R                  R                  nTT:H  nU(       a  [#        U4S	 jU R                  R                  R                  R$                   5       5      n	U	S
:  a^  U R                  R&                  (       dC  UR                  [        R                  " SU < SU< S3SU R                  R                  SS95        GO[#        U4S jU R                  R                  R                  R$                   5       5      n
[#        U4S jU R                  R                  R                  R$                   5       5      nU
S:  aW  U R                  R&                  (       d<  UR                  [        R                  " SU < SU< S3S[(        < SU< S3U SS95        US:  aW  U R                  R&                  (       d<  UR                  [        R                  " SU < SU< S3S[(        < SU< S3U SS95        U
S:X  d  US:X  aF  UR                  [        R                  " SU < SU< SU< S3U R                  R                  S S95        U R                  R&                  Gb8  [+        U R                  R&                  5      S
:  a<  U R                  R&                  S   (       a  U R                  R&                  S   (       d+  UR                  [        R                  " S!U-  S"U S#S95        U$ Tc   S5       eTU R                  R                  U R                  R                  pnU R                  R&                  S S
 u  nnX4UU44 GHO  u  nn/ nUR                  R$                   HN  n[        US$5      (       d  M  [-        UR                  S%S 5      U:X  d  M3  UR                  UR.                  5        MP     U(       a/  S&UR                  R                  < S'S(R1                  U5      < S)3nOS n UR                  R3                  U5      n[        US$5      (       a  [-        UR                  S%S 5      U:X  d^  UR                  [        R                  " S*UR                  R                  < SU< S+UR                  R                  < S3UU S,S95        GMO  GMR     U$ ! [4        R6                   a4    UR                  [        R                  " S-U< S.U< S3UU S/S95         GM  f = f)0Nr2   r.   Tinclude_auto_createdzYField specifies a many-to-many relation through model '%s', which has not been installed.zfields.E331r   zvManyToManyField with intermediate tables cannot be checked if you don't pass the model where the field is attached to.c              3   X   >#    U  H  nT[        UR                  S S5      :H  v   M!     g7frC   Nr   r\   r<   r   
from_models     r6   r>   <ManyToManyField._check_relationship_model.<locals>.<genexpr>  ,       !G '%*<*<gt"LL!G   '*   z/The model is used as an intermediate model by 'z-', but it has more than two foreign keys to 'zy', which is ambiguous. You must specify which two foreign keys Django should use via the through_fields keyword argument.zGUse through_fields to specify which two foreign keys Django should use.zfields.E333rk   c              3   X   >#    U  H  nT[        UR                  S S5      :H  v   M!     g7frd  re  rf  s     r6   r>   rh    ri  rj  c              3   X   >#    U  H  nT[        UR                  S S5      :H  v   M!     g7frd  re  )r<   r   rJ  s     r6   r>   rh    s,      !G (:(:GT JJ!Grj  r   z.', but it has more than one foreign key from 'zt', which is ambiguous. You must specify which foreign key Django should use via the through_fields keyword argument.zEIf you want to create a recursive relationship, use ManyToManyField("z", through="z").zfields.E334z,', but it has more than one foreign key to 'zfields.E335r   z*', but it does not have a foreign key to 'r   rz   zfields.E336zField specifies 'through_fields' but does not provide the names of the two link fields that should be used for the relation through model '%s'.zMMake sure you specify 'through_fields' as through_fields=('field1', 'field2')zfields.E337r\   rC   z3Did you mean one of the following foreign keys to 'z': r'  ?r)  z' is not a foreign key to 'zfields.E339zThe intermediary model 'z' has no field 'zfields.E338)r   r\   r=  r2   r3   r   r   r   r   r|   r   rs   r7   rC   rt   r0   r1   sumr   rR  r/   r   r   ru   r/  r  r	   r  )r,   rg  rE   qualified_model_namer~   from_model_nameto_model_namerelationship_model_nameself_referential	seen_self	seen_fromseen_torq  r=  targetsource_field_nametarget_field_namer   r^   possible_field_namesr1  rl   r   rJ  s    `                     @r6   rV  )ManyToManyField._check_relationship_model  s   4$$,,g66!!))//99!!))22$ 
 $(#4#4#<#< $$DIINN,E,E!% -F -
 
 MM:<PQ$	 ) 2) (
D4E4E4K4KLH(..::O(C(( ( ( : :&*&7&7&?&?&E&E&Q&Q#)X5  !%!2!2!:!:!@!@!G!G  	
 q=):):)I)IMM  $_6!5 !% 1 1 9 9,&    !%!2!2!:!:!@!@!G!G  	  !%!2!2!:!:!@!@!G!G 
 q=):):)I)IMM  $_6 !@ 7" !%,%. Q;t'8'8'G'GMM
 CG	W !@ 7" !%,( >W\MM  $_mE !% 1 1 9 9, ++7 D%%445:%%44Q7%%44Q7LL?AUVB !(
p M "- 6- %%--%%++ "(
 8<7H7H7W7WQ84!#4
 '/&/2-J ,.($]]11#A~66 ' F- W077? 2 ,
 !. 3 3 ? ? $		*> ?	   $ ' 7 7
 C $E>:: '(:(:GT J,!- #MM & )0(A(A(2(5(;(;(G(G	%& *.(,'4
!"!-M2n = &77 	"LL#7!E%)$(#0 	s   (XAYYc                    [        U R                  R                  [        5      (       d/  U R                  R                  R                  R
                  (       d  / $ U R                  R                  R                  SS9 Vs0 s HR  nX R                  R                  :w  d  M  UR                  R
                  (       d  M;  UR                  R                  U_MT     nnU R                  5       nUR                  U5      nU(       Ga  UR                  R                  U R                  R                  R                  R                  :w  a  UR                  R                  (       a=  S nUR                  R                  R                  nUR                  < SU" U5      < 3nOUR                  R                  n[        R                   (       a  ["        R$                  SpSU-  n
O["        R&                  SpS n
U" SU< S	U< S
3U U
U	S9/$ / $ s  snf )NTra  c                     U R                   R                  R                   R                   H*  nUR                  R                  U L d  M  UR
                  s  $    g r;   )r2   rC  r   r\   r=  ru   )rC   r   s     r6   _get_field_name@ManyToManyField._check_table_uniqueness.<locals>._get_field_name  sA    !&!9!9!?!?!L!L --55>#(::- "Mr8   r.   zfields.W344zvYou have configured settings.DATABASE_ROUTERS. Verify that the table of %r is correctly routed to a separate database.zfields.E340z The field's intermediary table 'z"' clashes with the table name of 'rz   )rm   rl   rn   )r0   r\   r=  r1   r2   r<  r   r   r   rB  m2m_db_tabler  r  rC  r   r   DATABASE_ROUTERSr   r  rs   )r,   rE   rC   registered_tablesr  r  r   clashing_objerror_classerror_id
error_hints              r6   rX  'ManyToManyField._check_table_uniqueness  s   t((00#66$$,,22::I 222M
M))111 (6;kk6I6I (EKK  %'M 	 

 ((*!%%l3 **  ((..==> {{''.
 {{//55*.**oe6LM${{00(((.X "./  )/mX!
-9<I#  	Y
s    H!H>Hc                   > [         TU ]  5       u  pp4U R                  b  U R                  US'   U R                  R                  SLa  U R                  R                  US'   [        U R                  R                  [        5      (       a  SU R                  R                  ;   aB  U R                  R                  R                  S5      u  pVU< SUR                  5       < 3US'   OUU R                  R                  R                  5       US'   O-U R                  R                  R                  R                  US'   [        U R                  SS 5      b  [        U R                  R                  [        5      (       a  U R                  R                  US'   O\U R                  R                  R                  R                  (       d-  U R                  R                  R                  R                  US'   U R                   nUbZ  [#        US   S5      (       a4  US   R$                  U:w  a!  ['        SUS   R$                  < S	U< S
35      e[)        US   U5      US'   XX44$ )NrB  Tr  r.   r
  r=  r6  zjCannot deconstruct a ManyToManyField pointing to a model that is swapped in place of more than one model (r7  r8  )rS   r   rB  r\   r  r0   rC   r1   r9  r   r2   r:  r   r=  rC  r   r   r   r6  r;  r   r<  s	           r6   r   ManyToManyField.deconstruct  s   #(7#6#8 D==$!%F:**$6&*&7&7&E&EF?#d''--s33d''---(,(9(9(?(?(E(Ec(J%	*3Z5E5E5GHt#0066<<>t,,2288DDF4L4$$i6B$++33S99$($5$5$=$=y!&&..44AA$($5$5$=$=$C$C$I$Iy! !22(vd|^44$<,,0AA$ *0)B)BDUW  -t!F4L 4''r8   c                    U R                   R                  nUR                  R                  U R	                  5       5      nUR                  R                  U R                  5       5      nU(       a2  UR                  nU(       a  UR                  U5      nO>UR                  nO1UR                  nU(       a  UR                  U5      nOUR                  nUS   R                  nUS   R                  n	XL a  / n
O\[        UR                  U	R                  5      (       a  UR                  U	R                  5      n
OU	R                  UR                  5      n
/ UQU
QUQ$ )z1Called by both direct and indirect m2m traversal.r   r   )r\   r=  r2   r  m2m_field_namem2m_reverse_field_namer  r  r   r  r  
issubclassrC   get_path_to_parentget_path_from_parent)r,   r  r  	int_model
linkfield1
linkfield2
join1infos
join2infosjoin1_finaljoin2_initialintermediate_infoss              r6   _get_path_infoManyToManyField._get_path_info  s-   %%--	__..t/B/B/DE
__..t/J/J/LM
#66J '556GH
'22
#66J '556GH
'22
 !n,,"1//'!#))=+>+>??!,!?!?@S@S!T!.!C!CKDUDU!V>>0>:>>r8   c                 "    U R                  SUS9$ )NTr  r  r  r,   r  s     r6   r  ManyToManyField.get_path_info  s    ""$BS"TTr8   c                 "    U R                  5       $ r;   r  r]   s    r6   r   ManyToManyField.path_infos  r  r8   c                 "    U R                  SUS9$ )NFr  r  r  s     r6   r  %ManyToManyField.get_reverse_path_info  s    ""%CT"UUr8   c                 "    U R                  5       $ r;   r  r]   s    r6   r  "ManyToManyField.reverse_path_infos  r  r8   c                    U R                   R                  b*  U R                   R                  R                  R                  $ U R                  (       a  U R                  $ [        R
                  " UR                  5      < SU R                  < 3n[        R                  " U[        R                  R                  5       5      $ )zO
Function that can be curried to provide the m2m table name for this
relation.
ry   )r\   r=  r2   rB  r   strip_quotesru   truncate_namer
   opsmax_name_length)r,   r   m2m_table_names      r6   rG  !ManyToManyField._get_m2m_db_table  s    
 $$0$$,,22;;;]]== (-(:(:4==(I499UN&&~z~~7U7U7WXXr8   c           	         SU-  n[        X5      (       a  [        X5      $ U R                  R                  b  U R                  R                  S   nOSnU R                  R                  R
                  R                   Hp  nUR                  (       d  M  UR                  R                  UR                  :X  d  M<  Ub  XER                  :X  d  MP  [        X[        XR5      5        [        X5      s  $    g)zb
Function that can be curried to provide the source accessor or DB
column name for the m2m table.
z_m2m_%s_cacheNr   )r   r   r\   rR  r=  r2   r   is_relationrC   r^   ru   r  )r,   r   attr
cache_attrlink_field_namer1  s         r6   _get_m2m_attrManyToManyField._get_m2m_attr,  s    
 %t+
4$$4,,++7"//>>qAO"O""**0077ANN((G,A,AA$,660I'!*:;t00 8r8   c           	      f   SU-  n[        X5      (       a  [        X5      $ SnU R                  R                  b  U R                  R                  S   nOSnU R                  R                  R
                  R                   H  nUR                  (       d  M  UR                  R                  UR                  :X  d  M<  Uc<  UR                  UR                  :X  a"  U(       a  [        X[        Xb5      5          O1SnM{  Ub  XVR                  :X  d  M  [        X[        Xb5      5          O   [        X5      $ )zc
Function that can be curried to provide the related accessor or DB
column name for the m2m table.
z_m2m_reverse_%s_cacheFNr   T)r   r   r\   rR  r=  r2   r   r  rC   r^   r  ru   )r,   r   r  r  foundr  r1  s          r6   _get_m2m_reverse_attr%ManyToManyField._get_m2m_reverse_attrA  s    
 -t3
4$$4,,++7"//>>qAO"O""**0077A}}}!5!5!F"*w/D/D/U
 '!2BC $$,660IDga.>? 8 t((r8   c           	        > U R                   R                  (       aa  U R                   R                  [        :X  d.  U R                   R                  UR                  R
                  :X  a  SU-  U R                   l        OeU R                   R                  (       aJ  SUR                  R                  < SUR                  R                  5       < SU< S3U R                   l        [        TU ]0  " X40 UD6  UR                  R                  (       ds  U R                   R                  (       a#  S n[        XAU R                   R                  U S9  O5UR                  R                   (       d  [#        X5      U R                   l        [%        XR&                  [)        U R                   SS95        [+        U R,                  UR                  5      U l        g )Nz%s_rel_+ry   z_+c                 $    XR                   l        g r;   )r\   r=  )ry   rC   r   s      r6   resolve_through_modelBManyToManyField.contribute_to_class.<locals>.resolve_through_model  s    16&&.r8   r   Freverse)r\   rQ  rC   r/   r2   rt   rU   r{   r3   r   r   rS   r   r   r=  rI   r   rM  r  ru   r   r   rG  r  )r,   r   ru   rE   r  rX   s        r6   r   #ManyToManyField.contribute_to_class_  sR    ((##'FF  &&#))*?*??-7$->D*%%% 		##""$.D* 	#C88 yy!!  ((7 ')0A0A0I0IQU YY&&,R-!!)
 	YY 4T5F5FPU VW $D$:$:CIIFr8   c           	      B  ^^ U R                   R                  (       dN  UR                  R                  R                  (       d)  [        UUR                  [        U R                   SS95        [        U R                  US5      U l
        [        U R                  US5      U l        [        U R                  US5      U l        [        U R                  US5      U l        [        U R                  US5      mU4S jU l        [        U R                  US5      mU4S jU l        g )NTr  ri  ru   r\   c                  &   > T " 5       R                   $ r;   r   )get_m2m_rels   r6   <lambda>=ManyToManyField.contribute_to_related_class.<locals>.<lambda>  s    []-E-Er8   c                  &   > T " 5       R                   $ r;   r  )get_m2m_reverse_rels   r6   r  r    s    5H5J5U5Ur8   )r\   r{   r^   r2   r   r  r   r   r   r  m2m_column_namer  m2m_reverse_namer  r  m2m_target_field_namem2m_reverse_target_field_name)r,   r   r   r  r  s      @@r6   r   +ManyToManyField.contribute_to_related_class  s       ''0E0E0K0K0S0S%%$T%6%6E  't'9'97HM '(B(BGX V%d&8&8'6J&-&&'
# d00'>J%E"%&&
 .V*r8   c                     g r;   rO   r]   s    r6   r   'ManyToManyField.set_attributes_from_rel  s    r8   c                 x    UR                   c  / $ [        [        XR                  5      R	                  5       5      $ r;   )r   listr   r   all)r,   rm   s     r6   value_from_object!ManyToManyField.value_from_object  s,    VV^rOgc<<.H.L.L.N)OOr8   c                 L    [        XR                  5      R                  U5        g r;   )r   r   setr4  s      r6   r6  ManyToManyField.save_form_data  s    ,,'++D1r8   r  c                L  > [         R                  U R                  R                  R                  R                  U5      S.UEnUR                  S5      b;  US   n[        U5      (       a  U" 5       nU Vs/ s H  oUR                  PM     snUS'   [        TU ](  " S0 UD6$ s  snf )N)r  r  initialrO   )r   ModelMultipleChoiceFieldr\   rC   r	  r  r  r   r   rS   r   )r,   r  rE   r   r  irX   s         r6   r   ManyToManyField.formfield  s    88))//@@FFuM
 
 <<	".y)G  !)18"9A44"9HYw ,8,, #:s   6B!c                     g r;   rO   r   s     r6   r  ManyToManyField.db_check  r  r8   c                     g r;   rO   r   s     r6   r   ManyToManyField.db_type  r   r8   c                     S S S.$ )N)r  ra   rO   r   s     r6   r  ManyToManyField.db_parameters  s    t,,r8   )
rB  rS  r  r  r  r  r  r  r  r   )	NNNNNNTNTr;   )FN)(r   r   r   r   r   r   r   r   r   r)   r  ry   r*  rT   ra   r  rW  rV  rX  r   r  r  r   r   r  r  rG  r  r  r   r   r   r  r6  r   r  r   r  r   r   r   s   @r6   rO  rO  %  s     LKKJI/0K
 9#v
	&PdL2h&(P?>U $ $V , ,Y1*)</GbV4P2 "& - -
- -r8   rO  )Hr  r  rn  r   djangor   django.appsr   django.confr   r   django.corer   r	   rF  r
   r   django.db.backendsr   django.db.modelsr   django.db.models.constantsr   django.db.models.deletionr   r   r   django.db.models.query_utilsr   django.db.models.utilsr   django.utils.deprecationr   django.utils.functionalr   django.utils.translationr   ry   r  r   mixinsr   related_descriptorsr   r   r   r   r   r    related_lookupsr!   r"   r#   r$   r%   r&   r'   reverse_relatedr(   r)   r*   r+   r/   r7   rI   rK   r  register_lookupr  r,  rM  rO  rO   r8   r6   <module>r     s.         3 * ( $  1 D D 1 3 = 3 6  #    X W"( 2O*g?E gTL D   i (   l +   o .   0 1   7 8   4 5   m ,g4 g4T	/J /d6rf
-l f
-r8   