
    h+	                     N    d dl mZ d dlmZ d dlmZ d dlmZ d Zd Z	d Z
d
dZy	)    )ContentType)DEFAULT_DB_ALIAS)PolymorphicModelBase)PolymorphicModelc                     |j                  dt              }|j                  dd      }t        |  } |rt        |       } | D ]  }t        j
                  j                  |      j                  |d      }|j
                  j                  |      }|r|j                  d      }|r |j                  d	i |}|j                  |        y)
a#  
    Set the polymorphic content-type ID field to the proper model
    Sort the ``*models`` from base class to descending class,
    to make sure the content types are properly assigned.

    Add ``ignore_existing=True`` to skip models which already
    have a polymorphic content type.
    usingignore_existingF)for_concrete_modelT)polymorphic_ctype__isnull)polymorphic_ctypeN )
popr   sort_by_subclassreversedr   objects
db_managerget_for_modelfilterupdate)modelsfiltersr   r	   	new_modelnew_ctqss          A/home/dcms/DCMS/lib/python3.12/site-packages/polymorphic/utils.pyreset_polymorphic_ctyper      s     KK!12Ekk"3U;Ov&F &! 
,	$$//6DD% E 
 ))%0T:B%W%B
		F	+
,    c                     | |u ry	 | j                         j                  |      }	 |j                         j                  |       }||kD  ||k  z
  S # t        $ r Y yw xY w# t        $ r Y yw xY w)Nr      )mroindex
ValueError)cls1cls2index1index2s       r   _compare_mror(   '   s~    t|!!$'!!$' VO00  
  s"   A A  	AA 	A,+A,c                  <    ddl m} t        |  |t                    S )z=
    Sort a series of models by their inheritance order.
    r   )
cmp_to_key)key)	functoolsr*   sortedr(   )classesr*   s     r   r   r   8   s     %'z,788r   c                     t        | j                               D ]8  }t        |t              s|t        us|s|j
                  j                  r6|c S  y)zk
    First the first concrete model in the inheritance chain that inherited from the PolymorphicModel.
    N)r   r!   
isinstancer   r   _metaabstract)
ChildModelallow_abstractModels      r   get_base_polymorphic_modelr6   A   sL     *..*+ u23--u{{';';L r   N)F)"django.contrib.contenttypes.modelsr   	django.dbr   polymorphic.baser   polymorphic.modelsr   r   r(   r   r6   r   r   r   <module>r;      s%    : & 1 /,>1"9r   