
    h                    H   S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
Jr  SSKJrJrJrJr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJ r    " S S\5      r!S r" " S S5      r# " S S\#5      r$ " S S5      r% " S S5      r&S r' " S S\&5      r(S r)g)a
  
Accessors for related objects.

When a field defines a relation between two models, each model class provides
an attribute to access related instances of the other model class (unless the
reverse accessor has been disabled with related_name='+').

Accessors are implemented as descriptors in order to customize access and
assignment. This module defines the descriptor classes.

Forward accessors follow foreign keys. Reverse accessors trace them back. For
example, with the following models::

    class Parent(Model):
        pass

    class Child(Model):
        parent = ForeignKey(Parent, related_name='children')

 ``child.parent`` is a forward many-to-one relation. ``parent.children`` is a
reverse many-to-one relation.

There are three types of relations (many-to-one, one-to-one, and many-to-many)
and two directions (forward and reverse) for a total of six combinations.

1. Related instance on the forward side of a many-to-one relation:
   ``ForwardManyToOneDescriptor``.

   Uniqueness of foreign key values is irrelevant to accessing the related
   instance, making the many-to-one and one-to-one cases identical as far as
   the descriptor is concerned. The constraint is checked upstream (unicity
   validation in forms) or downstream (unique indexes in the database).

2. Related instance on the forward side of a one-to-one
   relation: ``ForwardOneToOneDescriptor``.

   It avoids querying the database when accessing the parent link field in
   a multi-table inheritance scenario.

3. Related instance on the reverse side of a one-to-one relation:
   ``ReverseOneToOneDescriptor``.

   One-to-one relations are asymmetrical, despite the apparent symmetry of the
   name, because they're implemented in the database with a foreign key from
   one table to another. As a consequence ``ReverseOneToOneDescriptor`` is
   slightly different from ``ForwardManyToOneDescriptor``.

4. Related objects manager for related instances on the reverse side of a
   many-to-one relation: ``ReverseManyToOneDescriptor``.

   Unlike the previous two classes, this one provides access to a collection
   of objects. It returns a manager rather than an instance.

5. Related objects manager for related instances on the forward or reverse
   sides of a many-to-many relation: ``ManyToManyDescriptor``.

   Many-to-many relations are symmetrical. The syntax of Django models
   requires declaring them on one side but that's an implementation detail.
   They could be declared on the other side without any change in behavior.
   Therefore the forward and reverse descriptors can be the same.

   If you're looking for ``ForwardManyToManyDescriptor`` or
   ``ReverseManyToManyDescriptor``, use ``ManyToManyDescriptor`` instead.
    N)sync_to_async)
FieldError)DEFAULT_DB_ALIASNotSupportedErrorconnectionsroutertransaction)ManagerQWindowsignals)	RowNumber)GreaterThanLessThanOrEqual)QuerySet)DeferredAttribute)
AltersDataresolve_callables)RemovedInDjango60Warning)cached_propertyc                       \ rS rSrS rSrg)ForeignKeyDeferredAttributeX   c                 $   UR                   R                  U R                  R                  5      U:w  a;  U R                  R	                  U5      (       a  U R                  R                  U5        X!R                   U R                  R                  '   g N)__dict__getfieldattname	is_cacheddelete_cached_valueselfinstancevalues      ]/var/www/html/env/lib/python3.13/site-packages/django/db/models/fields/related_descriptors.py__set__#ForeignKeyDeferredAttribute.__set__Y   sl      !3!34=$**BVBVC
 C
 JJ**8405$**,,-     N)__name__
__module____qualname____firstlineno__r'   __static_attributes__r*   r)   r&   r   r   X   s    6r)   r   c                 t   [        S0 U S3U0D6nU R                  =(       d    [        nU R                  R                  (       a  [
        U   R                  R                  (       d  [        S5      eU R                  R                  U R                  R                  peU R                  R                  US9R                  5        VVs/ s H  u  pxUPM	     n	nn[        [        5       XS9n
U[        X5      -  nUb  U[!        X5      -  nU R                  R#                  5         U R%                  U5      $ s  snnf )N__inz`Prefetching from a limited queryset is only supported on backends that support window functions.)using)partition_byorder_byr*   )r   _dbr   query	is_slicedr   featuressupports_over_clauser   low_mark	high_markget_compilerget_order_byr   r   r   r   clear_limitsfilter)queryset
field_name	instances	predicatedbr:   r;   expr_r4   windows              r&   _filter_prefetch_querysetrH   a   s   5
|4()45I		))B~~2''<<#1  'nn55x~~7O7O) ( ; ;" ; E R R T
 TWTD T 	 
 	*P[22	 ;;I##%??9%%
s   D4c                   j    \ rS rSrSrS r\S 5       rS rS r	SS jr
SS	 jrS
 rSS jrS rS rSrg)ForwardManyToOneDescriptorv   a.  
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

    class Child(Model):
        parent = ForeignKey(Parent, related_name='children')

``Child.parent`` is a ``ForwardManyToOneDescriptor`` instance.
c                     Xl         g r   r   )r#   field_with_rels     r&   __init__#ForwardManyToOneDescriptor.__init__   s    #
r)   c           	      .   [        SU R                  R                  R                  R                  [
        4U R                  R                  R                  U R                  R                  R                  < SU R                  R                  < S3S.5      $ NRelatedObjectDoesNotExist.z.RelatedObjectDoesNotExist)r,   r-   )	typer   remote_fieldmodelDoesNotExistAttributeErrorr,   r-   namer#   s    r&   rS   4ForwardManyToOneDescriptor.RelatedObjectDoesNotExist   so    
 'ZZ$$**77H"jj..99 JJ$$11JJOO!
 	
r)   c                 8    U R                   R                  U5      $ r   )r   r    r#   r$   s     r&   r    $ForwardManyToOneDescriptor.is_cached   s    zz##H--r)   c                     U R                   R                  R                  R                  R	                  US9R                  5       $ Nhints)r   rV   rW   _base_manager
db_managerallr#   rc   s     r&   get_queryset'ForwardManyToOneDescriptor.get_queryset   s5    zz&&,,::EEEERVVXXr)   Nc                     [         R                  " S[        SS9  Uc  U R                  U5      $ U R                  X/5      $ NzLget_prefetch_queryset() is deprecated. Use get_prefetch_querysets() instead.   )
stacklevelwarningswarnr   get_prefetch_querysetsr#   rB   r@   s      r&   get_prefetch_queryset0ForwardManyToOneDescriptor.get_prefetch_queryset   E    $		
 ..y99**9jAAr)   c                    U(       a  [        U5      S:w  a  [        S5      eU(       a  US   OU R                  5       nUR                  US   S9  U R                  R
                  nU R                  R                  nU Vs0 s H  oe" U5      U_M     nnU R                  R                  S   nU R                  R                  n	U	R                  (       d#  [        U R                  R                  5      S:X  a+  SUR                  -  U Vs1 s H  oe" U5      S   iM     sn0n
OSU R                  R                  5       -  U0n
UR                  " S0 U
D6nUR                  R                  5         U	R                  (       d$  U H  nXt" U5         nU	R!                  X5        M      UUUSU R                  R"                  S4$ s  snf s  snf 	N   Iquerysets argument of get_prefetch_querysets() should have a length of 1.r   r$   %s__inTFr*   )len
ValueErrorrh   
_add_hintsr   get_foreign_related_valueget_local_related_valueforeign_related_fieldsrV   hiddenrZ   related_query_namer?   r6   clear_orderingmultipleset_cached_value
cache_name)r#   rB   	querysetsr@   rel_obj_attrinstance_attrinstinstances_dictrelated_fieldrV   r6   rel_objr$   s                r&   rq   1ForwardManyToOneDescriptor.get_prefetch_querysets   s   Y1,  $-9Q<$2C2C2EYq\2zz;;

::@IJ	--t3	J

99!<zz.. #djj&G&G"HA"M$$%JS&T)$}T':1'=)&TE
 

 = = ??KE??+U+ 	%%' $$#),w*?@--g@ $ JJ!!
 	
9 K 'Us    F>	Gc                 t    U R                  US9nUR                  U R                  R                  U5      5      $ Nrz   )rh   r   r   get_reverse_related_filter)r#   r$   qss      r&   
get_object%ForwardManyToOneDescriptor.get_object   s3    1vvdjj;;HEFFr)   c                 \   Uc  U $  U R                   R                  U5      nUcf  U R                   R                  (       dK  U R                  U R                   R                  R                  < SU R                   R                  < S35      eU$ ! [         Ga    SU R                   R                  U5      ;  nU(       a/  UR                  R                  U R                   R                  5      OSnU(       aB  UR                  U5      (       a,  UR                  U5      nU R                   R                  USS9nOSnUcP  U(       aI  U R                  U5      nU R                   R                  nUR                  (       d  UR                  X15        U R                   R                  X5         GNf = f)a  
Get the related instance through the forward relation.

With the example above, when getting ``child.parent``:

- ``self`` is the descriptor managing the ``parent`` attribute
- ``instance`` is the ``child`` instance
- ``cls`` is the ``Child`` class (we don't need it)
Ndefault has no rT   )r   get_cached_valueKeyErrorr   _metaget_ancestor_linkrW   r    r   rV   r   r   nullrS   r+   rZ   )r#   r$   clsr   	has_valueancestor_linkancestorrV   s           r&   __get__"ForwardManyToOneDescriptor.__get__   s^    K
	;jj11(;G6 ?4::??00#'::#3#3#<#<djjooN  N?  	;DJJ$F$Fx$PPI  001A1AB 
 !8!8!B!B )99(C **55h5M9//(3#zz66 $,, 11'DJJ'':1	;s   B DF+*F+c                    Ub  [        X R                  R                  R                  R                  R
                  5      (       dv  [        SU< SUR                  R                  < SU R                  R                  < SU R                  R                  R                  R                  R                  < S3	5      eUb  UR                  R                  c.  [        R                  " UR                  US9UR                  l
        UR                  R                  c.  [        R                  " UR                  US9UR                  l
        [        R                  " X!5      (       d  [        SU-  5      eU R                  R                  nUce  U R                  R                  USS	9nUb  UR!                  US5        U R                  R"                   H  u  pV[%        XR&                  S5        M     OHU R                  R"                   H.  u  pV[%        XR&                  [)        X&R&                  5      5        M0     U R                  R!                  X5        Ub$  UR*                  (       d  UR!                  X!5        ggg)
a(  
Set the related instance through the forward relation.

With the example above, when setting ``child.parent = parent``:

- ``self`` is the descriptor managing the ``parent`` attribute
- ``instance`` is the ``child`` instance
- ``value`` is the ``parent`` instance on the right of the equal sign
NCannot assign "": "rT   " must be a "" instance.rz   GCannot assign "%r": the current database router prevents this relation.r   )
isinstancer   rV   rW   r   concrete_modelr}   object_namerZ   _staterD   r   db_for_write	__class__allow_relationr   r   related_fieldssetattrr   getattrr   )r#   r$   r%   rV   relatedlh_fieldrh_fields          r&   r'   "ForwardManyToOneDescriptor.__set__  s    Z::**0066EE&
 &
  NN..JJOOJJ++1177CC  !!)%+%8%8&&&" ||&"("5"5OOh# ((99  "'( 
 zz..
 = jj11(D1IG
 "--gt<&*jj&?&?""2"2D9 '@
 '+jj&?&?""2"2GECSCS4TU '@
 	

##H4
 \%:%:))%: &;r)   c                 f    [         U R                  R                  U R                  R                  44$ )z
Pickling should return the instance attached by self.field on the
model, not a new copy of that descriptor. Use getattr() to retrieve
the instance directly from the model.
)r   r   rW   rZ   r[   s    r&   
__reduce__%ForwardManyToOneDescriptor.__reduce__]  s&     ))4::??;;;r)   rM   r   )r+   r,   r-   r.   __doc__rO   r   rS   r    rh   rs   rq   r   r   r'   r   r/   r*   r)   r&   rJ   rJ   v   sO    
$ 
 
".Y	B.
`G
1fJ;X<r)   rJ   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )ForwardOneToOneDescriptorif  a  
Accessor to the related object on the forward side of a one-to-one relation.

In the example::

    class Restaurant(Model):
        place = OneToOneField(Place, related_name='restaurant')

``Restaurant.place`` is a ``ForwardOneToOneDescriptor`` instance.
c                 T  >^ U R                   R                  R                  (       a  UR                  5       nU R                   R                  R                  nUR
                  R                   Vs/ s H  oDR                  PM     snm[        U4S jU 5       5      (       do  T Vs0 s H  oD[        X5      _M     nnU" S0 UD6nUR                  R                  UR                  l        UR                  R                  UR                  l        U$ [        TU ]9  U5      $ s  snf s  snf )Nc              3   ,   >#    U  H	  oT;   v   M     g 7fr   r*   ).0r   fieldss     r&   	<genexpr>7ForwardOneToOneDescriptor.get_object.<locals>.<genexpr>}  s     =H5Hs   r*   )r   rV   parent_linkget_deferred_fieldsrW   r   concrete_fieldsr   anyr   r   addingrD   superr   )	r#   r$   deferred	rel_modelr   kwargsobjr   r   s	          @r&   r   $ForwardOneToOneDescriptor.get_objectr  s    ::""..335H 

//55I1:1P1PQ1Pmm1PQF
 =H===GMNve!99vN)&)$,OO$:$:

! ( 2 2


w!(++ R Os   0D &D%c                    > [         TU ]  X5        U R                  R                  (       a  U R                  R                  R
                  (       a  UR                  nUR                   Vs/ s H+  nUR                  (       d  M  UR                  (       d  M)  UPM-     nnU HS  nUR                  R                  R                  R                  R                  nUb  [        X&5      OS n[        XU5        MU     g g g s  snf r   )r   r'   r   primary_keyrV   r   r   r   rW   pkr   r   r   )	r#   r$   r%   optsr   inherited_pk_fieldsrel_model_pk_name	raw_valuer   s	           r&   r'   !ForwardOneToOneDescriptor.__set__  s    ( ::!!djj&=&=&I&I>>D "11#1E$$ ).);); 1   #
 -$)$6$6$<$<$B$B$E$E$M$M!9>9JGE5PT  Y? - 'J!#s   +C;C;C;r*   )	r+   r,   r-   r.   r   r   r'   r/   __classcell__r   s   @r&   r   r   f  s    	,&@ @r)   r   c                   d    \ rS rSrSrS r\S 5       rS rS r	SS jr
SS	 jrSS
 jrS rS rSrg)ReverseOneToOneDescriptori  a  
Accessor to the related object on the reverse side of a one-to-one
relation.

In the example::

    class Restaurant(Model):
        place = OneToOneField(Place, related_name='restaurant')

``Place.restaurant`` is a ``ReverseOneToOneDescriptor`` instance.
c                     Xl         g r   r   )r#   r   s     r&   rO   "ReverseOneToOneDescriptor.__init__  s	     r)   c           	         [        SU R                  R                  R                  [        4U R                  R
                  R                  U R                  R
                  R                  < SU R                  R                  < S3S.5      $ rR   )	rU   r   related_modelrX   rY   rW   r,   r-   rZ   r[   s    r&   rS   3ReverseOneToOneDescriptor.RelatedObjectDoesNotExist  sk     '\\''44nE"ll00;; LL&&33LL%%!
 	
r)   c                 8    U R                   R                  U5      $ r   )r   r    r^   s     r&   r    #ReverseOneToOneDescriptor.is_cached  s    ||%%h//r)   c                 x    U R                   R                  R                  R                  US9R	                  5       $ ra   )r   r   rd   re   rf   rg   s     r&   rh   &ReverseOneToOneDescriptor.get_queryset  s/    ||))77BBBOSSUUr)   Nc                     [         R                  " S[        SS9  Uc  U R                  U5      $ U R                  X/5      $ rk   rn   rr   s      r&   rs   /ReverseOneToOneDescriptor.get_prefetch_queryset  ru   r)   c                    U(       a  [        U5      S:w  a  [        S5      eU(       a  US   OU R                  5       nUR                  US   S9  U R                  R
                  R                  nU R                  R
                  R                  nU Vs0 s H  oe" U5      U_M     nnSU R                  R
                  R                  -  U0nUR                  " S0 UD6nUR                  R                  5         U H2  n	Xt" U	5         n
U R                  R
                  R                  X5        M4     UUUSU R                  R                  S4$ s  snf rw   )r|   r}   rh   r~   r   r   r   r   rZ   r?   r6   r   r   r   )r#   rB   r   r@   r   r   r   r   r6   r   r$   s              r&   rq   0ReverseOneToOneDescriptor.get_prefetch_querysets  s:   Y1,  $-9Q<$2C2C2EYq\2||))AA**DD@IJ	--t3	JDLL..333Y???+U+ 	%%'  G%l7&;<HLL//B   LL##
 	
 Ks   Ec                 z   Uc  U $  U R                   R                  U5      nUcA  U R                  UR                  R                  < SU R                   R                  < S35      eU$ ! [         a    UR                  nUc  SnOU R                   R                  R                  U5      n U R                  US9R                  " S0 UD6nU R                   R                  R                  X15        O,! U R                   R                  R                   a    Sn Of = fU R                   R                  X5         GNf = f)aQ  
Get the related instance through the reverse relation.

With the example above, when getting ``place.restaurant``:

- ``self`` is the descriptor managing the ``restaurant`` attribute
- ``instance`` is the ``place`` instance
- ``cls`` is the ``Place`` class (unused)

Keep in mind that ``Restaurant`` holds the foreign key to ``Place``.
Nrz   r   rT   r*   )r   r   r   r   r   get_forward_related_filterrh   r   r   r   rX   rS   r   r+   accessor_name)r#   r$   r   r   
related_pkfilter_argss         r&   r   !ReverseOneToOneDescriptor.__get__  s$    K
	=ll33H=G$ ?00%%..0J0JL 
 N/  	=!J!"ll00KKHUK"///BFFUUG LL&&77J ||11>> #"G# LL))(<	=s6   A( (AD:*C/	&D:/&DD:DD:9D:c                   ^ Ucd  U R                   R                  TSS9nUbF  U R                   R                  T5        [        X0R                   R                  R
                  S5        gg[        X R                   R                  5      (       dl  [        SU< STR                  R                  < SU R                   R                  < SU R                   R                  R                  R                  < S3	5      eTR                  R                  c.  [        R                  " TR                   US9TR                  l        UR                  R                  c.  [        R                  " UR                   TS9UR                  l        [        R"                  " UT5      (       d  [        S	U-  5      e[%        U4S
 jU R                   R                  R&                   5       5      n[)        U R                   R                  R*                  5       H  u  pV[        X&R,                  XE   5        M     U R                   R/                  TU5        U R                   R                  R/                  UT5        g)a~  
Set the related instance through the reverse relation.

With the example above, when setting ``place.restaurant = restaurant``:

- ``self`` is the descriptor managing the ``restaurant`` attribute
- ``instance`` is the ``place`` instance
- ``value`` is the ``restaurant`` instance on the right of the equal sign

Keep in mind that ``Restaurant`` holds the foreign key to ``Place``.
Nr   r   r   rT   r   r   rz   r   c              3   P   >#    U  H  n[        TUR                  5      v   M     g 7fr   )r   r   )r   r   r$   s     r&   r   4ReverseOneToOneDescriptor.__set__.<locals>.<genexpr>P  s&      FE %--00Fs   #&)r   r   r!   r   r   rZ   r   r   r}   r   r   r   r   rD   r   r   r   r   tupler   	enumeratelocal_related_fieldsr   r   )r#   r$   r%   r   r   indexr   s    `     r&   r'   !ReverseOneToOneDescriptor.__set__  s     = ll33Hd3KG" 00: !3!3!8!8$? # E<<#=#=>> NN..LL..LL..44@@  !!)%+%8%8&&&" ||&"("5"5OOh# ((99  "'( 
  !\\//FF J !*$,,*<*<*Q*Q R}}j.?@ !S
 LL))(E: LL//x@r)   c                 f    [         U R                  R                  U R                  R                  44$ r   )r   r   rW   rZ   r[   s    r&   r   $ReverseOneToOneDescriptor.__reduce__a  s&    ++T\\->->???r)   r   r   )r+   r,   r-   r.   r   rO   r   rS   r    rh   rs   rq   r   r'   r   r/   r*   r)   r&   r   r     sK    

 
 
 0V	B
@+ZEAN@r)   r   c                   D    \ rS rSrSrS r\S 5       rS
S jrS r	S r
S	rg)ReverseManyToOneDescriptorif  a  
Accessor to the related objects manager on the reverse side of a
many-to-one relation.

In the example::

    class Child(Model):
        parent = ForeignKey(Parent, related_name='children')

``Parent.children`` is a ``ReverseManyToOneDescriptor`` instance.

Most of the implementation is delegated to a dynamically defined manager
class built by ``create_forward_many_to_many_manager()`` defined below.
c                 2    Xl         UR                  U l        g r   )relr   )r#   r   s     r&   rO   #ReverseManyToOneDescriptor.__init__v  s    YY
r)   c                     U R                   R                  n[        UR                  R                  U R                   5      $ r   )r   r   "create_reverse_many_to_one_manager_default_managerr   r#   r   s     r&   related_manager_cls.ReverseManyToOneDescriptor.related_manager_clsz  s4    ..1**44HH
 	
r)   Nc                 .    Uc  U $ U R                  U5      $ )a	  
Get the related objects through the reverse relation.

With the example above, when getting ``parent.children``:

- ``self`` is the descriptor managing the ``children`` attribute
- ``instance`` is the ``parent`` instance
- ``cls`` is the ``Parent`` class (unused)
)r  )r#   r$   r   s      r&   r   "ReverseManyToOneDescriptor.__get__  s      K''11r)   c                 2    SU R                   R                  4$ )Nzreverse side of a related set)r   r   r[   s    r&   _get_set_deprecation_msg_params:ReverseManyToOneDescriptor._get_set_deprecation_msg_params  s    +HH""
 	
r)   c                 :    [        SU R                  5       -  5      e)Nz@Direct assignment to the %s is prohibited. Use %s.set() instead.)	TypeErrorr  r"   s      r&   r'   "ReverseManyToOneDescriptor.__set__  s#    N2245
 	
r)   )r   r   r   )r+   r,   r-   r.   r   rO   r   r  r   r  r'   r/   r*   r)   r&   r   r   f  s/     
 
2

r)   r   c                 2   ^^  " UU4S jSU [         5      mT$ )z
Create a manager for the reverse side of a many-to-one relation.

This manager subclasses another manager, generally the default manager of
the related model, and adds behaviors specific to many-to-one relations.
c                   4  >^  \ rS rSrU U4S jrU4S jrSrS rS rS r	U 4S jr
SS	 jrSU 4S
 jjrSS.S jrS\l        SS.S jrS\l        UU 4S jrS\l        S rS\l        UU 4S jrS\l        S rS\l        UU 4S jrS\l        S rS\l         YR,                  R.                  (       aB  SS.S jrS\l        SS.S jrS\l        SS.S jrS\l        SS.S jrS\l        S rS\l        SSS.S jrS\l        SSS.S jrS\l        SrU =r $ ):create_reverse_many_to_one_manager.<locals>.RelatedManageri  c                    > [         TU ]  5         Xl        TR                  U l        TR
                  U l        U R
                  R                  U0U l        g r   )r   rO   r$   r   rW   r   rZ   core_filters)r#   r$   r   r   s     r&   rO   Ccreate_reverse_many_to_one_manager.<locals>.RelatedManager.__init__  s@    G$M**DJDJ!%( ;Dr)   c                   > [        U R                  U5      n[        UR                  T5      nU" U R                  5      $ r   )r   rW   r   r   r$   )r#   managermanager_classr   s      r&   __call__Ccreate_reverse_many_to_one_manager.<locals>.RelatedManager.__call__  s5    djj'2G>w?P?PRUVM //r)   Tc                     U R                   R                   HK  n[        U R                  UR                  5      b  M&  [        SU R                  < SUR                   S35      e   g )N"#" needs to have a value for field "z'" before this relationship can be used.)r   r   r   r$   r   r}   )r#   r   s     r&   _check_fk_valHcreate_reverse_many_to_one_manager.<locals>.RelatedManager._check_fk_val  s[    ::4==%--8@$DMM, -!MM?*QS  ;r)   c           
         U R                   =(       d)    [        R                  " U R                  U R                  S9n[
        U   R                  R                  nUR                  U R                  S9  U R                   (       a  UR                  U R                   5      nSUl
        UR                  " S0 U R                  D6nU R                  R                   HG  n[        U R                  UR                   5      nUb  US:X  d  M.  U(       d  M7  UR#                  5       s  $    U R                  R$                  (       aU   U R                  R&                  n[        U R                  UR                   5      nU R                  XpR                  00Ul        U$ ! [(         ad    [+        U R                  R,                  S   R.                   Vs/ s H#  n[        U R                  UR                   5      PM%     Os  snf sn5      n Nf = f)@
Filter the queryset for the instance this manager is bound to.
rz   T r*   )r5   r   db_for_readrW   r$   r   r8   !interprets_empty_strings_as_nullsr~   r2   _defer_next_filterr?   r  r   r   r   r   nonemany_to_onetarget_fieldr   r   
path_infostarget_fields_known_related_objects)r#   r@   rD   empty_strings_as_nullr   valr&  
rel_obj_ids           r&   _apply_rel_filtersMcreate_reverse_many_to_one_manager.<locals>.RelatedManager._apply_rel_filters  s    SV//

T]]SB$/%h88 " 7xx#>>$((3*.H';):):;H::dmmU]];;3"91F1F#==?* ; zz%%
N#'::#:#:L ")8L8L!MJJJ]] ;3/ O "  "' 15

0E0Eb0I0W0W0W $DMM<3G3GH0W"Js   ?F 4H	*G4
3HHc                      U R                   R                  R                  U R                  R                  R
                  5        g ! [        [        4 a     g f = fr   )r$   _prefetched_objects_cachepopr   rV   r   rY   r   r[   s    r&   _remove_prefetched_objectsUcreate_reverse_many_to_one_manager.<locals>.RelatedManager._remove_prefetched_objects  sK    77;;JJ++66 #H- s   AA AAc                 f  > U R                   R                  c-  [        U R                   R                  R                  < S35      e U R                   R
                  U R                  R                  R                     $ ! [        [        4 a"    [        TU ]1  5       nU R                  U5      s $ f = f)NzQ instance needs to have a primary key value before this relationship can be used.)r$   r   r}   r   r+   r0  r   rV   r   rY   r   r   rh   r-  )r#   r@   r   s     r&   rh   Gcreate_reverse_many_to_one_manager.<locals>.RelatedManager.get_queryset  s     }}' }}..77: ;N O 9}}>>JJ++66  #H- 9 7/1..x889s   6A> >/B0/B0c                     [         R                  " S[        SS9  Uc  U R                  U5      $ U R                  X/5      $ rk   rn   rr   s      r&   rs   Pcreate_reverse_many_to_one_manager.<locals>.RelatedManager.get_prefetch_queryset  E    MM(	 229==..y*EEr)   c                   > U(       a  [        U5      S:w  a  [        S5      eU(       a  US   O[        TU ]  5       nUR	                  US   S9  UR                  UR                  =(       d    U R                  5      nU R                  R                  nU R                  R                  nU Vs0 s H  oe" U5      U_M     nn[        X0R                  R                  U5      nU HO  nU R                  R                  U5      (       a  M%  Xt" U5         n	[        XR                  R                  U	5        MQ     U R                  R                  R                  n
X4USU
S4$ s  snf )Nrx   ry   r   rz   F)r|   r}   r   rh   r~   r2   r5   r   r   r   rH   rZ   r    r   rV   r   )r#   rB   r   r@   r   r   r   r   r   r$   r   r   s              r&   rq   Qcreate_reverse_many_to_one_manager.<locals>.RelatedManager.get_prefetch_querysets  s*   S^q0 #  (1y|eg6J6LH16~~hll&>dhh?H::==L JJ@@MDMNIDmD147INN0::??IVH $zz++G44-l7.CDHGZZ__h? $ 00;;J=%URR Os   -Ebulkc                  ^  T R                  5         T R                  5         [        R                  " T R                  T R
                  S9nU 4S jnU(       a  / nU Hi  nU" U5        UR                  R                  (       d  UR                  R                  U:w  a  [        SU-  5      eUR                  UR                  5        Mk     T R                  R                  R                  U5      R                  US9R                  " S0 T R                   R"                  T R
                  0D6  g [$        R&                  " USS9   U H  nU" U5        UR)                  5         M     S S S 5        g ! , (       d  f       g = f)Nrz   c                    > [        U TR                  5      (       d1  [        STR                  R                  R                  < SU < 35      e[        U TR                  R                  TR                  5        g )N'' instance expected, got )	r   rW   r  r   r   r   r   rZ   r$   )r   r#   s    r&   check_and_update_obj\create_reverse_many_to_one_manager.<locals>.RelatedManager.add.<locals>.check_and_update_obj)  sX    !#tzz22# !JJ,,88  TZZ__dmm<r)   zA%r instance isn't saved. Use bulk=False or save the object first.pk__inFr2   	savepointr*   )r  r2  r   r   rW   r$   r   r   rD   r}   appendr   rd   r2   r?   updater   rZ   r	   atomicsave)r#   r<  objsrD   rA  pksr   s   `      r&   add>create_reverse_many_to_one_manager.<locals>.RelatedManager.add$  s&    ++-$$TZZ$--HB	= C(-zz((CJJMMR,?(0256  JJsvv&   

((..r2999ELL 

 !''bEB#,S1
  $ CBBs   "E,,
E:c                T   #    [        U R                  5      " USU06I S h  vN $  N7fNr<  r   rM  r#   r<  rK  s      r&   aadd?create_reverse_many_to_one_manager.<locals>.RelatedManager.aaddK  s$     &txx0$BTBBBB   (&(c                   > U R                  5         U R                  5         U R                  XR                  R                  '   [
        R                  " U R                  U R                  S9n[        TU R                  U5      ]*  " S0 UD6$ Nrz   r*   )r  r2  r$   r   rZ   r   r   rW   r   re   creater#   r   rD   RelatedManagerr   s      r&   rX  Acreate_reverse_many_to_one_manager.<locals>.RelatedManager.createP  sg     ++-&*mmF::??#$$TZZ$--HB)<DNvNNr)   c                 T   #    [        U R                  5      " S0 UD6I S h  vN $  N7fNr*   r   rX  r#   r   s     r&   acreateBcreate_reverse_many_to_one_manager.<locals>.RelatedManager.acreateY  s"     &t{{3=f====rU  c                    > U R                  5         U R                  XR                  R                  '   [        R
                  " U R                  U R                  S9n[        TU R                  U5      ]&  " S0 UD6$ rW  )
r  r$   r   rZ   r   r   rW   r   re   get_or_createrY  s      r&   rc  Hcreate_reverse_many_to_one_manager.<locals>.RelatedManager.get_or_create^  s[     &*mmF::??#$$TZZ$--HB)<KUfUUr)   c                 T   #    [        U R                  5      " S0 UD6I S h  vN $  N7fr]  r   rc  r_  s     r&   aget_or_createIcreate_reverse_many_to_one_manager.<locals>.RelatedManager.aget_or_createf  s$     &t'9'9:DVDDDDrU  c                    > U R                  5         U R                  XR                  R                  '   [        R
                  " U R                  U R                  S9n[        TU R                  U5      ]&  " S0 UD6$ rW  )
r  r$   r   rZ   r   r   rW   r   re   update_or_createrY  s      r&   rj  Kcreate_reverse_many_to_one_manager.<locals>.RelatedManager.update_or_createk  s\     &*mmF::??#$$TZZ$--HB)<NXQWXXr)   c                 T   #    [        U R                  5      " S0 UD6I S h  vN $  N7fr]  r   rj  r_  s     r&   aupdate_or_createLcreate_reverse_many_to_one_manager.<locals>.RelatedManager.aupdate_or_creates  s$     &t'<'<=GGGGGrU  c                n   U(       d  g U R                  5         U R                  R                  U R                  5      n[	        5       nU H  n[        XPR                  5      (       d1  [        SU R                  R                  R                  < SU< 35      eU R                  R                  U5      U:X  a  UR                  UR                  5        M  U R                  R                  R                  R                  U< SU R                  < S35      e   U R                  U R!                  US9U5        g )Nr?  r@  z is not related to rT   rC  )r  r   r   r$   setr   rW   r  r   r   r   rM  r   rV   rX   _clearr?   )r#   r<  rK  r+  old_idsr   s         r&   removeAcreate_reverse_many_to_one_manager.<locals>.RelatedManager.remove|  s    ""$jj::4==I%C%c::66' !%

 0 0 < < #  zz99#>#ECFF+"jj55;;HH:=t}}M     DKKwK7>r)   c                T   #    [        U R                  5      " USU06I S h  vN $  N7frP  r   rt  rR  s      r&   aremoveBcreate_reverse_many_to_one_manager.<locals>.RelatedManager.aremove  s$     *4;;7IDIIIIrU  c                F    U R                  5         U R                  X5        g r   )r  rr  r#   r<  s     r&   clear@create_reverse_many_to_one_manager.<locals>.RelatedManager.clear  s    ""$D'r)   c                P   #    [        U R                  5      " US9I S h  vN $  N7f)Nr;  r   r|  r{  s     r&   aclearAcreate_reverse_many_to_one_manager.<locals>.RelatedManager.aclear  s     *4::6DAAAAs   &$&c                    U R                  5         [        R                  " U R                  U R                  S9nUR                  U5      nU(       a)  UR                  " S0 U R                  R                  S 0D6  g [        R                  " USS9   U HG  n[        X@R                  R                  S 5        UR                  U R                  R                  /S9  MI     S S S 5        g ! , (       d  f       g = f)Nrz   FrE  )update_fieldsr*   )r2  r   r   rW   r$   r2   rH  r   rZ   r	   rI  r   rJ  )r#   r@   r<  rD   r   s        r&   rr  Acreate_reverse_many_to_one_manager.<locals>.RelatedManager._clear  s    //1((dmmL#>>"-OO>tzz&=>$++"F#+C#C$?HHDJJOO3DHE $, GFFs   AC''
C5F)r<  r|  c                   U R                  5         [        U5      nU R                  R                  (       a  [        R
                  " U R                  U R                  S9n[        R                  " USS9   U(       a"  U R                  US9  U R                  " USU06  O[        U R                  U5      R                  5       5      n/ nU H,  nXu;   a  UR                  U5        M  UR!                  U5        M.     U R                  " USU06  U R                  " USU06  S S S 5        g U R                  " USU06  g ! , (       d  f       g = f)Nrz   FrE  r;  r<  )r  r   r   r   r   r   rW   r$   r	   rI  r|  rM  rq  r2   rf   rt  rG  )r#   rK  r<  r|  rD   old_objsnew_objsr   s           r&   rq  >create_reverse_many_to_one_manager.<locals>.RelatedManager.set  s     ;Dzz((dmmL ''bEB


-$2T2#&tzz"~'9'9';#<#%#'C" ( 4 ( 4	 $( X9D9(66 CB  $*T*! CBs   5B*D;;
E	c                R   #    [        U R                  5      " XUS9I S h  vN $  N7f)N)rK  r<  r|  r   rq  )r#   rK  r<  r|  s       r&   aset?create_reverse_many_to_one_manager.<locals>.RelatedManager.aset  s!     &txx0dUSSSS   '%')r  r   r$   rW   r   )!r+   r,   r-   r.   rO   r  do_not_call_in_templatesr  r-  r2  rh   rs   rq   rM  alters_datarS  rX  r`  rc  rg  rj  rn  r   r   rt  rx  r|  r  rr  rq  r  r/   r   )r   rZ  r   s   @r&   rZ  r    sP   	<	0
 $( 	&	P		9"		F	S0 #' #	#J )- 	C  	O "	> #	V %)!	E &*"	Y (,$	H )-% 99>>)- ?0 "&F04 J #'G$( ( !%E+/ B "&FF "&F$( 	+4 +/u 	T  r)   rZ  r   )
superclassr   rZ  s    `@r&   r   r     s"    m  m Z m ^	 r)   c                   V   ^  \ rS rSrSrSU 4S jjr\S 5       r\S 5       r	S r
SrU =r$ )	ManyToManyDescriptori  a  
Accessor to the related objects manager on the forward and reverse sides of
a many-to-many relation.

In the example::

    class Pizza(Model):
        toppings = ManyToManyField(Topping, related_name='pizzas')

``Pizza.toppings`` and ``Topping.pizzas`` are ``ManyToManyDescriptor``
instances.

Most of the implementation is delegated to a dynamically defined manager
class built by ``create_forward_many_to_many_manager()`` defined below.
c                 0   > [         TU ]  U5        X l        g r   )r   rO   reverse)r#   r   r  r   s      r&   rO   ManyToManyDescriptor.__init__  s    r)   c                 .    U R                   R                  $ r   )r   throughr[   s    r&   r  ManyToManyDescriptor.through  s    
 xxr)   c                     U R                   (       a  U R                  R                  OU R                  R                  n[	        UR
                  R                  U R                  U R                   S9$ )Nr  )r  r   r   rW   #create_forward_many_to_many_managerr  r   r  s     r&   r  (ManyToManyDescriptor.related_manager_cls  sK    26,,..DHHNN2**44HHLL
 	
r)   c                     SU R                   (       a  SOS-  U R                   (       a  U R                  R                  4$ U R                  R                  4$ )Nz%s side of a many-to-many setr  forward)r  r   r   r   rZ   r[   s    r&   r  4ManyToManyDescriptor._get_set_deprecation_msg_params   sI    + LLyi9&*llDHH""
 	
 9=


 	
r)   r  )F)r+   r,   r-   r.   r   rO   propertyr  r   r  r  r/   r   r   s   @r&   r  r    s?     
     
 

 
r)   r  c                 :   ^ ^^^  " UUUU 4S jST [         5      mT$ )z
Create a manager for the either side of a many-to-many relation.

This manager subclasses another manager, generally the default manager of
the related model, and adds behaviors specific to many-to-many relations.
c                   d  >^  \ rS rSrS'U UU4S jjrUU4S jrSrS rS rS r	S	 r
U 4S
 jrS'S jrS'U 4S jjr\S 5       rU U4S jrU U4S jrSS.S jrS\l        SS.S jrS\l        S rS\l        S rS\l        U 4S jrS\l        S rS\l        SSS.S jrS\l        SSS.S jrS\l        SS.UU 4S jjrS\l        SS.S jrS\l        SS.UU 4S jjrS\l        SS.S jrS\l        SS.UU 4S jjrS\l        SS.S  jr S\ l        S! r!S" r"S# r#SS.S$ jr$U 4S% jr%S&r&U =r'$ )(?create_forward_many_to_many_manager.<locals>.ManyRelatedManageri  Nc                   > [         TU ]  5         Xl        T(       d  TR                  U l        TR                  R                  5       U l        TR                  R                  U l        TR                  R                  5       U l
        TR                  R                  5       U l        TR                  U l        OTR                  U l        TR                  R                  U l        TR                  R                  5       U l        TR                  R                  5       U l
        TR                  R                  5       U l        SU l        TR                  U l        TU l        U R                  R"                  R%                  U R                  5      U l        U R                  R"                  R%                  U R                  5      U l        0 U l        0 U l        U R&                  R.                   Hg  u  p#U R                  < SUR                  < 3n[1        XR2                  5      U R*                  U'   UR                  U R,                  UR                  '   Mi     U R&                  R5                  U5      U l        S U R6                  ;   a+  [9        SU< SU R,                  U R                     < S35      eUR:                  c"  [9        SUR<                  R>                  -  5      eg )NF__r  r  z4" before this many-to-many relationship can be used.z]%r instance needs to have a primary key value before a many-to-many relationship can be used.) r   rO   r$   rW   r   r   query_field_namerZ   prefetch_cache_namem2m_field_namesource_field_namem2m_reverse_field_nametarget_field_namesymmetricalr   r  r  r   	get_fieldsource_fieldr&  r  pk_field_namesr   r   r   r   related_valr}   r   r   r+   )r#   r$   r   r   core_filter_keyr   r   r  s        r&   rO   Hcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.__init__  s4   G$M YY
(+		(D(D(F%+.99>>(),)A)A)C&),)I)I)K&#&??  ..
(+		%+.99+G+G+I(),)I)I)K&),)A)A)C&#( ;;DL"DL $ 2 2 < <T=S=S TD $ 2 2 < <T=S=S TD "D"$D&*&7&7&F&F".2.C.CX]]"S5<XGWGW5X!!/25=]]##HMM2 'G
  $00JJ8TDt'''   !4!4T5K5K!LN  {{" ?((112  #r)   c                ~   > [        U R                  U5      n[        UR                  TT5      nU" U R                  S9$ r   )r   rW   r  r   r$   )r#   r  r  r   r  s      r&   r  Hcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.__call__C  s;    djj'2G?!!3M !$--88r)   Tc                    [         R                  " U R                  U R                  4/5      n[	        U[
        5      (       + =(       d    UR                  5       nU(       a)  U[         R                  " U R                   S3U4/5      -  nU R                  (       aa  [         R                  " U R                  U R                  4/5      nU(       a)  U[         R                  " U R                   S3U4/5      -  nX$-  nU$ )Nr1   )	r   rX  r  r  r   r   _has_filtersr  r  )r#   removed_valsfiltersremoved_vals_filterssymmetrical_filterss        r&   _build_remove_filtersUcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._build_remove_filtersL  s    hh!7!79I9I JKLG |X66U,:S:S:U ! $188)?)?(@&E|%T$UVV&'hh,,d.>.>?@'# ('188!334D9<HI, ' .Nr)   c                     UR                  U R                  S9  U R                  (       a  UR                  U R                  5      nSUl        UR                  5       R                  " S0 U R                  D6$ )r  rz   Tr*   )r~   r$   r5   r2   r#  _next_is_stickyr?   r  )r#   r@   s     r&   r-  Rcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._apply_rel_filters`  s]     7xx#>>$((3*.H'++-44It7H7HIIr)   c                 v     U R                   R                  U R                     $ ! [        [        4 a     g f = fr   )r$   r0  r  rY   r   r[   s    r&   get_prefetch_cacheRcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_prefetch_cachej  s9    }}>>t?W?WXX"H- s   "% 88c                      U R                   R                  R                  U R                  5        g ! [        [
        4 a     g f = fr   )r$   r0  r1  r  rY   r   r[   s    r&   r2  Zcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._remove_prefetched_objectsp  s<    77;;D<T<TU"H- s   /2 AAc                 l   > U R                  5       =nb  U$ [        TU ]	  5       nU R                  U5      $ r   )r  r   rh   r-  )r#   cacher@   r   s      r&   rh   Lcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_querysetv  s:    0022? 7/1..x88r)   c                     [         R                  " S[        SS9  Uc  U R                  U5      $ U R                  X/5      $ rk   rn   rr   s      r&   rs   Ucreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_prefetch_queryset}  r8  r)   c                 $  >^^ U(       a  [        U5      S:w  a  [        S5      eU(       a  US   O[        T	U ]  5       nUR	                  US   S9  UR                  UR                  =(       d    U R                  5      n[        UR                  5       U R                  U5      nU R                  R                  R                  U R                  5      mTR                  R                  R                  n[         UR"                     mTR$                  R&                  nUR)                  TR*                   Vs0 s H0  nSUR,                  -  U" U5      < SU" UR.                  5      < 3_M2     snS9nUUU4S jUU4S	 jS
U R0                  S
4$ s  snf )Nrx   ry   r   rz   z_prefetch_related_val_%srT   )selectc                 F   >^  [        UU 4S jTR                   5       5      $ )Nc              3   v   >#    U  H.  nUR                  [        TS UR                   35      T5      v   M0     g7f)_prefetch_related_val_Nget_db_prep_valuer   r   )r   f
connectionresults     r&   r   {create_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_prefetch_querysets.<locals>.<lambda>.<locals>.<genexpr>  sE      %
 5	 ''*@(LM"  5s   69)r   r   )r  r  fks   `r&   <lambda>hcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_prefetch_querysets.<locals>.<lambda>  s    u %
  44%  r)   c                 F   >^  [        UU 4S jTR                   5       5      $ )Nc              3   p   >#    U  H+  nUR                  [        TUR                  5      T5      v   M-     g 7fr   r  )r   r  r  r   s     r&   r   r    s3      #6 ''aii(@*MM6s   36)r   r   )r   r  r  s   `r&   r  r    s    U #66# r)   F)r|   r}   r   rh   r~   r2   r5   rH   r  r  r  r   r  r  rW   db_tabler   rD   ops
quote_nameextrar   r   columnr  )
r#   rB   r   r@   
join_tableqnr  r  r  r   s
          @@r&   rq   Vcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_prefetch_querysets  sl   S^q0 #  (1y|eg6J6LH16~~hll&>dhh?H0((*D,A,A9H ##--d.D.DEB00J$X[[1J**B~~
  44	 5 /ii *~r!((|"55 5	 & H  (( s   57Fc                    U R                   R                  (       d  g [        R                  " U R                  U R
                  S9n[        U   R                  R                  (       d  g SU R
                  0nU R                  R                  R                  XS9nU R                  U R                  S   0nU R                   R                  (       a  SUSU R                  -  '   UR                  " S0 UD6$ )Nrz   r$   rb   r   Fz
%s__isnullr*   )r&  db_constraintr   r!  r  r$   r   r8   supports_foreign_keysrd   re   r  r  r   r  r?   )r#   rD   rc   r  r  s        r&   constrained_targetRcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.constrained_target  s    
 $$22##DLL4==IBr?++AA/Ell00;;B;LG--t/?/?/BCG   %%AFt'='==>>>,G,,r)   c                    > T[         L a0  U R                  5       c  U R                  =nb  UR                  5       $ [        TU ]  5       $ r   )r
   r  r  existsr   r#   r  r   r  s     r&   r  Fcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.exists  sH    g%++-5+/+B+BB'O)0022w~''r)   c                    > T[         L a0  U R                  5       c  U R                  =nb  UR                  5       $ [        TU ]  5       $ r   )r
   r  r  countr   r  s     r&   r  Ecreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.count  sG    g%++-5+/+B+BB'O)//11w}&r)   through_defaultsc                   U R                  5         [        R                  " U R                  U R                  S9n[
        R                  " USS9   U R                  " U R                  U R                  /UQ7SU06  U R                  (       a+  U R                  " U R                  U R                  /UQ7SU06  S S S 5        g ! , (       d  f       g = f)Nrz   FrE  r  )r2  r   r   r  r$   r	   rI  
_add_itemsr  r  r  )r#   r  rK  rD   s       r&   rM  Ccreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.add  s    ++-$$T\\DMMJB##">****  &6	 ##OO....  *:	 ?>>s   A(C  
Cc                T   #    [        U R                  5      " USU06I S h  vN $  N7f)Nr  rQ  )r#   r  rK  s      r&   rS  Dcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.aadd  s0     &txx0(8   rU  c                 t    U R                  5         U R                  " U R                  U R                  /UQ76   g r   )r2  _remove_itemsr  r  r#   rK  s     r&   rt  Fcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.remove  s0    ++-t55t7M7MUPTUr)   c                 N   #    [        U R                  5      " U6 I S h  vN $  N7fr   rw  r  s     r&   rx  Gcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.aremove  s     &t{{3T::::s   %#%c                   > [         R                  " U R                  U R                  S9n[        R
                  " USS9   [        R                  R                  U R                  SU R                  U R                  U R                  S US9  U R                  5         U R                  [        TU ]9  5       R                  U5      5      nU R                  R                   R                  U5      R#                  U5      R%                  5         [        R                  R                  U R                  SU R                  U R                  U R                  S US9  S S S 5        g ! , (       d  f       g = f)Nrz   FrE  	pre_clearsenderactionr$   r  rW   pk_setr2   
post_clear)r   r   r  r$   r	   rI  r   m2m_changedsendr  rW   r2  r  r   rh   r2   r  r?   delete)r#   rD   r  r   s      r&   r|  Ecreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.clear	  s   $$T\\DMMJB##">##((<<&!]] LL** )  //144UW5I5K5Q5QRT5UV--33B7>>wGNNP##((<<'!]] LL** )  ?>>s    DE
E,c                 R   #    [        U R                  5      " 5       I S h  vN $  N7fr   r  r[   s    r&   r  Fcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.aclear%  s     &tzz24444r  F)r|  r  c                   [        U5      n[        R                  " U R                  U R                  S9n[
        R                  " USS9   U(       a#  U R                  5         U R                  " USU06  O[        U R                  U5      R                  U R                  R                  R                  SS95      n/ nU H  n[        XpR                  5      (       a  U R                  R!                  U5      S   OU R                  R#                  U5      nX;   a  UR%                  U5        Mn  UR'                  U5        M     U R$                  " U6   U R                  " USU06  S S S 5        g ! , (       d  f       g = f)Nrz   FrE  r  Tflatr   )r   r   r   r  r$   r	   rI  r|  rM  rq  r2   values_listr&  r   r   rW   r   get_prep_valuert  rG  )	r#   rK  r|  r  rD   rs  r  r   fk_vals	            r&   rq  Ccreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.set*  s3    ;D$$T\\DMMJB##">JJLHHdF5EF!

222 --::BB 3 G  "H#  *#zz:: !--GGLQO!%!2!2!A!A#!F 
 ",#NN62$OOC0  $ KK)HHhJ9IJ1 ?>>s   
DE,,
E:c                R   #    [        U R                  5      " XUS9I S h  vN $  N7f)N)rK  r|  r  r  )r#   rK  r|  r  s       r&   r  Dcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.asetL  s+     &txx09I   r  c                   > [         R                  " U R                  R                  U R                  S9n[        TU R                  U5      ]  " S0 UD6nU R                  XAS9  U$ Nrz   r  r*   )r   r   r$   r   r   re   rX  rM  )r#   r  r   rD   new_objManyRelatedManagerr   s        r&   rX  Fcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.createS  sT    $$T]]%<%<t}}UB.0CKUfUGHHWH@Nr)   c                X   #    [        U R                  5      " SSU0UD6I S h  vN $  N7fNr  r*   r^  r#   r  r   s      r&   r`  Gcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.acreate[  s5     &t{{3 !15;      !*(*c                   > [         R                  " U R                  R                  U R                  S9n[        TU R                  U5      ]  " S0 UD6u  pEU(       a  U R                  XAS9  XE4$ r  )r   r   r$   r   r   re   rc  rM  r#   r  r   rD   r   createdr  r   s         r&   rc  Mcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.get_or_createb  sc    $$T]]%<%<t}}UB !3T__R5HW LC
 @<r)   c                X   #    [        U R                  5      " SSU0UD6I S h  vN $  N7fr  rf  r  s      r&   rg  Ncreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.aget_or_createo  s7     &t'9'9: !15;   r  c                   > [         R                  " U R                  R                  U R                  S9n[        TU R                  U5      ]   " S0 UD6u  pEU(       a  U R                  XAS9  XE4$ r  )r   r   r$   r   r   re   rj  rM  r  s         r&   rj  Pcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.update_or_createv  sm    $$T]]%<%<t}}UB "DOOB$7 )!')LC
 @<r)   c                X   #    [        U R                  5      " SSU0UD6I S h  vN $  N7fr  rm  r  s      r&   rn  Qcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager.aupdate_or_create  s7     &t'<'<= !15;   r  c           
         SSK Jn  [        5       nU R                  R                  R                  U5      nU GH,  n[        X`R                  5      (       a  [        R                  " X`R                  5      (       dJ  [        SU< SU R                  R                  R                  < SUR                  R                  < S35      eUR                  U5      S   nUc  [        SU< SU< S35      eUR                  U5        M  [        Xc5      (       a1  [!        S	U R                  R                  R"                  < S
U< 35      eUR                  UR%                  U5      5        GM/     U$ )zC
Return the set of ids of `objs` that the target field references.
r   )ModelzCannot add "z": instance is on database "z", value is on database "r  z": the value for field "z	" is Noner?  r@  )django.db.modelsr'  rq  r  r   r  r   rW   r   r   r$   r}   r   rD   r   rM  r  r   r  )r#   r  rK  r'  
target_idsr&  r   	target_ids           r&   _get_target_idsOcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._get_target_ids  s!    /J<<--778IJLc::..!00mmDD(  #DMM$8$8$;$;SZZ]]L 
 !- F Fs KA NI (("$57  NN9-++#::++77> 
 NN<#>#>s#CD+ , r)   c                     U R                   R                  R                  U5      R                  USS9R                  " S0 XR
                  S   SU-  U0D6nUR                  U5      $ )zW
Return the subset of ids of `objs` that aren't already assigned to
this relationship.
Tr
  r   r{   r*   )r  r  r2   r  r?   r  
difference)r#   r  r  rD   r)  valss         r&   _get_missing_target_idsWcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._get_missing_target_ids  sw     --33B7.T:  *+;+;A+> #44j  ((..r)   c                 V   U R                   R                  R                  SL=(       a    [        U   R                  R
                  nU R                  =(       d    X R                  :H  =(       a)    [        R                  R                  U R                   5      nUUU=(       a    U(       + 4$ )a/  
Return a boolean triple of the way the add should be performed.

The first element is whether or not bulk_create(ignore_conflicts)
can be used, the second whether or not signals must be sent, and
the third element is whether or not the immediate bulk insertion
with conflicts ignored can be performed.
F)r  r   auto_createdr   r8   supports_ignore_conflictsr  r  r   r  has_listeners)r#   rD   r  can_ignore_conflictsmust_send_signalss        r&   _get_add_planMcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._get_add_plan  s     ""//u< GO,,FF ! K 15K5K K!D&&44T\\B  %!%?.?*? r)   c                   U(       d  g [        [        U=(       d    0 5      5      nU R                  X$5      n[        R                  " U R
                  U R                  S9nU R                  Xa5      u  pxn	U	(       al  U R
                  R                  R                  U5      R                  U V
s/ s H,  n
U R
                  " S0 SU-  U R                  S   SU-  U
0D6PM.     sn
SS9  g U R                  XXe5      n[        R                  " USS9   U(       aK  [        R                   R#                  U R
                  SU R                  U R$                  U R&                  UUS	9  U R
                  R                  R                  U5      R                  U V
s/ s H.  n
U R
                  " S0 UDSU-  U R                  S   SU-  U
0D6PM0     sn
US9  U(       aK  [        R                   R#                  U R
                  S
U R                  U R$                  U R&                  UUS	9  S S S 5        g s  sn
f s  sn
f ! , (       d  f       g = f)Nrz   z%s_idr   T)ignore_conflictsFrE  pre_addr  post_addr*   )dictr   r+  r   r   r  r$   r8  r  r2   bulk_creater  r0  r	   rI  r   r  r  r  rW   )r#   r  r  r  rK  r)  rD   r6  r7  can_fast_addr*  missing_target_idss               r&   r  Jcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._add_items  sI    #$56F6L"$MN--.?FJ$$T\\DMMJBDHDVDVEA \ --33B7CC *4 *4I   '*; ;T=M=Ma=P '*; ;Y *4 &* D  !%!=!=!b" ##">$'',,#||(!% $"jj1  -  --33B7CC *<	 *<I  . !(*; ;T=M=Ma=P '*; ;Y *<	 &: D  %'',,#||)!% $"jj1  - 7 ?>!:	 ?>s&   -3H)BH35H.
AH3.H33
Ic                 J  > U(       d  g [        5       nU H_  n[        XPR                  5      (       a1  U R                  R	                  U5      S   nUR                  U5        MN  UR                  U5        Ma     [        R                  " U R                  U R                  S9n[        R                  " USS9   [        R                  R                  U R                  SU R                  U R                  U R                  UUS9  [         TU ]E  5       nUR%                  5       (       aE  UR'                  U5      R(                  " S	0 SU R                  R                  R*                  -  U0D6n	OUn	U R-                  U	5      n
U R                  R.                  R'                  U5      R)                  U
5      R1                  5         [        R                  R                  U R                  SU R                  U R                  U R                  UUS9  S S S 5        g ! , (       d  f       g = f)
Nr   rz   FrE  
pre_remover  r{   post_remover*   )rq  r   rW   r&  r   rM  r   r   r  r$   r	   rI  r   r  r  r  r   rh   r  r2   r?   r   r  r  r  )r#   r  r  rK  rs  r   r  rD   target_model_qsold_valsr  r   s              r&   r  Mcreate_forward_many_to_many_manager.<locals>.ManyRelatedManager._remove_items%  s   
  eGc::..!..HHMaPFKK'KK$  $$T\\DMMJB##">##((<<'!]] LL**" )  #('"6"8"//11.44R8??  #d&7&7&D&D&L&LLgV H  'H44X>--33B7>>wGNNP##((<<(!]] LL**" ) + ?>>s   7EH
H")r  r$   rW   r  r  r  r  r  r  r  r  r&  r  r  r   )(r+   r,   r-   r.   rO   r  r  r  r-  r  r2  rh   rs   rq   r  r  r  r  rM  r  rS  rt  rx  r|  r  rq  r  rX  r`  rc  rg  rj  rn  r+  r0  r8  r  r  r/   r   )r   r  r   r  r  s   @r&   r  r    s   0	 0	d	9 $( 	(	J			9		F0	d 
	- 
	-$	(	' /3 	( 59 	
  	V "	; #	4 !	5 "%*T 	K@ ,1D 	
  -1 	 	 "48 	
 #48 		  		  %)!;? 	
 &*"7; 		  		  (,$>B 	
 )-%	@	/&	D QUE	N/	 /	r)   r  r  )r  r   r  r  s   ```@r&   r  r    s"    D	 D	Z D	L r)   )*r   ro   asgiref.syncr   django.core.exceptionsr   	django.dbr   r   r   r   r	   r(  r
   r   r   r   django.db.models.functionsr   django.db.models.lookupsr   r   django.db.models.queryr   django.db.models.query_utilsr   django.db.models.utilsr   r   django.utils.deprecationr   django.utils.functionalr   r   rH   rJ   r   r   r   r   r  r  r*   r)   r&   <module>rS     s   ?B  & -  9 8 0 A + : @ = 36"3 6&*m< m<`0@ : 0@fJ@ J@Z6
 6
rwt	,
5 ,
^N	r)   