https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/models/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/models/__pycache__/base.cpython-310.pyc
o

3�a�_�@sddlZddlZddlZddlmZddlmZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZddlmZmZmZmZmZmZmZdd	lmZmZm Z m!Z!m"Z"dd
l#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*dd
l+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7m8Z8ddl9m:Z:m;Z;m<Z<m=Z=m>Z>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFmGZGddlHmIZJGdd�d�ZKeK�ZLdd�ZMdd�ZNGdd�deO�ZPGd d!�d!�ZQGd"d#�d#�ZRGd$d%�d%ePd&�ZSd0d'd(�ZTd)d*�ZUd+d,�ZVd-d.�ZWd/eW_XdS)1�N)�
partialmethod)�chain)�apps)�settings)�checks)�NON_FIELD_ERRORS�FieldDoesNotExist�
FieldError�MultipleObjectsReturned�ObjectDoesNotExist�ValidationError)�DEFAULT_DB_ALIAS�DJANGO_VERSION_PICKLE_KEY�
DatabaseError�
connection�connections�router�transaction)�NOT_PROVIDED�ExpressionWrapper�IntegerField�Max�Value��
LOOKUP_SEP)�CheckConstraint�UniqueConstraint)�CASCADE�	Collector)�ForeignObjectRel�
OneToOneField�lazy_related_operation�resolve_relation)�Coalesce)�Manager)�Options)�F�Q)�class_prepared�	post_init�	post_save�pre_init�pre_save)�make_model_tuple)�	force_str)�
make_hashable)�capfirst�
get_text_list)�gettext_lazyc@seZdZdd�Zdd�ZdS)�DeferredcC�dS�Nz<Deferred field>���selfr6r6�7/usr/lib/python3/dist-packages/django/db/models/base.py�__repr__+�zDeferred.__repr__cCr4r5r6r7r6r6r9�__str__.r;zDeferred.__str__N)�__name__�
__module__�__qualname__r:r<r6r6r6r9r3*sr3cCst|||d|j|fd��S)z�
    Create exception subclass. Used by ModelBase below.

    The exception is created in a way that allows it to be pickled, assuming
    that the returned exception class will be added as an attribute to the
    'attached_to' class.
    z%s.%s)r>r?)�typer?)�name�bases�module�attached_tor6r6r9�subclass_exception5s�rEcCst�|�o
t|d�S)N�contribute_to_class)�inspect�isclass�hasattr)�valuer6r6r9�_has_contribute_to_classCsrKcsHeZdZdZ�fdd�Zdd�Zdd�Zedd	��Zed
d��Z	�Z
S)�	ModelBasezMetaclass for all models.c#	s�t�j}dd�|D�}|s|||||�S|�d�}d|i}|�dd�}	|	dur+|	|d<|�dd�}
i}|��D]\}}
t|
�rD|
||<q7|
||<q7|||||fi|��}t|
dd�}|
pat|dd�}t|dd�}d}t�|�}t|d	d�dur�|dur�|s�td
||f��n|j	}|�
dt||��|s�|�
dtdt
dd
�|D��p�tf||d��|�
dtdt
dd
�|D��p�tf||d��|r�|js�t|d�s�|j|j_t|d�s�|j|j_|jj}|r�|r�|jr�td||jf��|��D]
\}}
|�
||
�q�t|jj|jj|jj�}dd�|D�}|�rad}dd�|D�D]-}|jj�r/|jj�r-td|���q|du�r8|}�q|jj|jju�rGtd|���q|du�rTtd|��|j�|�|jj|j_n||j_i}t|g|�D]7}t|d��sx�qn||k�r�|jj�s��qn|jjD]}t |t!��r�|j"j#�r�t$||j"j%�}||t&|�<�q��qnt'�}|�(�D�]}||v�s�t|d��s�|�)|j*��q�|jj|jj}|jj�s6|D]}|j+|v�r�t,d|j+||j-f��|�.|j+��q�|jj}t&|�}||v�r�||}n0|�s-d|jj/}t!|t0|ddd�}||v�r t,d|||j-f��t||��s,|�
||�nd}||jj1|<nI|jj1�2�} |D]9}|j+|v�rv|j+|j*v�rv|j+|v�rvt2�3|�}!|�
|j+|!�|j4�rv| ��D]\}}"||"k�rt|!| |<�qg�q>|jj1�)| �|jjD]/}|j+|v�r�|jj�s�t,d|j+||j-f���q�t2�3|�}|jj�s�d|_5|�
|j+|��q��q�dd�|jj6D�|j_6|�r�d|
_|
|_7|S|�8�|jj�9|jj:|�|S) NcSsg|]	}t|t�r|�qSr6)�
isinstancerL)�.0�br6r6r9�
<listcomp>O�z%ModelBase.__new__.<locals>.<listcomp>r>�
__classcell__�Meta�abstractF�_meta�	app_labelzfModel class %s.%s doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.�DoesNotExistcs�(�|]}t|d�r|jjs|jVqdS�rUN)rIrUrTrW�rN�xr6r6r9�	<genexpr>���
��
�z$ModelBase.__new__.<locals>.<genexpr>)rDr
csrXrY)rIrUrTr
rZr6r6r9r\�r]�ordering�
get_latest_byz'%s cannot proxy the swapped model '%s'.cSsh|]}|j�qSr6�rA�rN�fr6r6r9�	<setcomp>�sz$ModelBase.__new__.<locals>.<setcomp>cSsg|]	}t|d�r|�qS)rU)rI)rN�klsr6r6r9rP�rQzOAbstract base class containing model fields not permitted for proxy model '%s'.zAProxy model '%s' has more than one non-abstract model base class.z6Proxy model '%s' has no non-abstract model base class.zRLocal field %r in class %r clashes with field of the same name from base class %r.z%s_ptrT)�	on_deleterA�auto_created�parent_linkztAuto-generated field '%s' in class %r for parent_link to base class %r clashes with declared field of the same name.cSsg|]}t�|��qSr6)�copy�deepcopy)rN�idxr6r6r9rP6�);�super�__new__�pop�itemsrK�getattrr�get_containing_app_config�RuntimeError�label�add_to_classr%rE�tuplerr
rTrIr^rUr_�proxy�swapped�	TypeErrorr�local_fields�local_many_to_many�private_fields�fields�concrete_model�setup_proxy�reversedrMr �remote_fieldrgr"�modelr-�set�mro�update�__dict__rAr	r=�add�
model_namer�parentsrhri�
one_to_one�
mti_inherited�indexesrS�_prepare�register_modelrV)#�clsrArB�attrs�kwargs�	super_newr�rC�	new_attrs�	classcell�	attr_meta�contributable_attrs�obj_name�obj�	new_classrT�meta�	base_metarV�
app_config�is_proxy�
new_fields�field_names�base�parent�parent_links�field�related�inherited_attributes�
parent_fields�base_key�	attr_name�base_parents�	new_fieldrg��	__class__r6r9rmJsz



������	���
	



�

��
�
��
���	

�
����

�
����


�zModelBase.__new__cCs(t|�r|�||�dSt|||�dS�N)rKrF�setattr)r�rArJr6r6r9rtDszModelBase.add_to_classcCs|j}|�|�|jr,t|jdd�|_t|jdd�|_|jjr,|j}|jj}t	t
||�|jdurBd|jd�
dd�|jD��f|_tj�|j�}|rQt|d	|�|jsqtd
d�|jD��retd|j��t�}d|_|�d|�|jjD]
}|js|�|�qutj|d
�dS)z7Create some methods once self._meta has been populated.T)�is_nextFNz%s(%s)�, cs��|]}|jVqdSr�r`rar6r6r9r\_��z%ModelBase._prepare.<locals>.<genexpr>�get_absolute_urlcss�|]}|jdkVqdS)�objectsNr`rar6r6r9r\f��zOModel %s must specify a custom Manager, because it has a field named 'objects'.r�)�sender)rUr��order_with_respect_tor�_get_next_or_previous_in_order�get_next_in_order�get_previous_in_orderr�r�r!�make_foreign_order_accessors�__doc__r=�joinr|r�ABSOLUTE_URL_OVERRIDES�get�label_lowerr��managers�any�
ValueErrorr$rfrtr�rA�set_name_with_modelr(�send)r��opts�wrt�remote�get_absolute_url_override�manager�indexr6r6r9r�Js:

"��
�zModelBase._preparecC�|jjSr�)rU�base_manager�r�r6r6r9�
_base_managerx�zModelBase._base_managercCr�r�)rU�default_managerr�r6r6r9�_default_manager|r�zModelBase._default_manager)r=r>r?r�rmrtr��propertyr�r�rRr6r6r�r9rLHs{.
rLc@seZdZddd�ZdS)�ModelStateFieldsCacheDescriptorNcCs|dur|Si}|_|Sr�)�fields_cache)r8�instancer��resr6r6r9�__get__�s
z'ModelStateFieldsCacheDescriptor.__get__r�)r=r>r?r�r6r6r6r9r��sr�c@seZdZdZdZdZe�ZdS)�
ModelStatezStore model instance state.NT)r=r>r?r��db�addingr�r�r6r6r6r9r��s

r�csheZdZ�fdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdtdd�Z
dd�Zee
e�Zdd�Zdudd�Zdd�Z		dvdd �Zd!e_		dwd"d#�Zd!e_d$d%�Z		dxd&d'�Zd(d)�Zd*d+�Zd,d-�Zdyd.d/�Zd!e_d0d1�Zd2d3�Zd4d5�Zd6d7�Z d8d9�Z!dtd:d;�Z"dtd<d=�Z#d>d?�Z$d@dA�Z%dBdC�Z&dDdE�Z'dzdFdG�Z(dtdHdI�Z)edJdK��Z*edLdM��Z+edNdO��Z,edPdQ��Z-edRdS��Z.edTdU��Z/edVdW��Z0edXdY��Z1edZd[��Z2ed\d]��Z3ed^d_��Z4ed`da��Z5edbdc��Z6eddde��Z7edfdg��Z8edhdi��Z9edjdk��Z:edldm��Z;edndo��Z<edpdq��Z=edrds��Z>�Z?S){�Modelcsf|j}|j}t}t}|jrtd��tj|||d�t�|_	t
|�t
|j�kr*td��|sHt
|j�}t||�D]\}}	||ur?q6|||	j|�q6n"t
|j�}t||�D]\}}	||ur[qR|||	j|�|�|	jd�qR|D]t}	d}
|	j|vr{|	jdur{ql|r�t|	jt�r�z
|�|	j�}d}
Wn9ty�z|�|	j�}Wn
ty�|	��}YnwYnwz|�|	j�}Wnty�|	��}Ynw|	��}|
r�||ur�|||	j|�ql||ur�|||	j|�ql|�r%|j}t|�D],}
z|
|vs�|�|
��r
||
|u�r|||
||
�||
=Wq�ttf�yYq�w|D]
}td|j|f��t�� �t!j||d�dS)Nz'Abstract models cannot be instantiated.)r��argsr�z'Number of args exceeds number of fieldsFTz,%s() got an unexpected keyword argument '%s')r�r�)"r�rUr��DEFERREDrTrxr+r�r��_state�len�concrete_fields�
IndexError�iter�zip�attnamer|rnrA�columnrMr�r�KeyError�get_default�_property_namesru�	get_field�AttributeErrorrr=rl�__init__r))r8r�r�r�r��_setattr�	_DEFERRED�fields_iter�valr��is_related_object�rel_obj�property_names�prop�kwargr�r6r9r��s�
�
��������
zModel.__init__csPt|�t|jj�krt|����fdd�|jjD�}||�}d|j_||j_|S)Ncs"g|]
}|j�vr
t��nt�qSr6)r��nextr�ra�r��values_iterr6r9rP�s��z!Model.from_db.<locals>.<listcomp>F)r�rUr�r�r�r�r�)r�r�r��values�newr6r�r9�from_db�s�z
Model.from_dbcCsd|jj|fS)Nz<%s: %s>)r�r=r7r6r6r9r:szModel.__repr__cCsd|jj|jfS)Nz%s object (%s))r�r=�pkr7r6r6r9r<sz
Model.__str__cCsBt|t�stS|jj|jjkrdS|j}|dur||uS||jkS�NF)rMr��NotImplementedrUr}r�)r8�other�my_pkr6r6r9�__eq__s

zModel.__eq__cCs|jdur	td��t|j�S)Nz8Model instances without primary key value are unhashable)r�rx�hashr7r6r6r9�__hash__s

zModel.__hash__cCs.|��}tj|t<|jj|jjf}t|f|fSr�)�__getstate__�django�__version__rrUrV�object_name�model_unpickle)r8�data�class_idr6r6r9�
__reduce__s
zModel.__reduce__cCs�|j��}t�|d�|d<|dj��|d_g}|��D]\}}t|t�r0|�|t|�f�q|rC||d<|D]	\}}|�|�q9|S)z0Hook to allow choosing the attributes to pickle.r��_memoryview_attrs)	r�rhr�rorM�
memoryview�append�bytesrn)r8�stater�attrrJr6r6r9r#s

�zModel.__getstate__cCs||�t�}|r|tjkrtjd|tjftdd�ntjdtdd�d|vr6|�d�D]
\}}t|�||<q+|j	�
|�dS)NzQPickled model instance's Django version %s does not match the current version %s.�)�
stacklevelz9Pickled model instance's Django version is not specified.r)r�rrr�warnings�warn�RuntimeWarningrnrr�r�)r8r�pickled_versionrrJr6r6r9�__setstate__4s(

����zModel.__setstate__NcCs|p|j}t||jj�Sr�)rUrpr�r�)r8r�r6r6r9�_get_pk_valJs
zModel._get_pk_valcCsD|jj��D]}|r||jjkrt||jj|�qt||jjj|�Sr�)rUr�r�r�r��target_fieldr�)r8rJrgr6r6r9�_set_pk_valNs
�zModel._set_pk_valcs�fdd��jjD�S)zU
        Return a set containing names of deferred fields for this instance.
        csh|]}|j�jvr|j�qSr6)r�r�rar7r6r9rcZs
�z,Model.get_deferred_fields.<locals>.<setcomp>)rUr�r7r6r7r9�get_deferred_fieldsVs
�zModel.get_deferred_fieldsc	s\|duri|_n*t|dd�}|D]}||vr||=|�|�q|s#dStdd�|D��r2tdt��d|i}|jjj||d�j	|j
d	�}|���|durVt|�}|j
|�}n�rh�fd
d�|jjD�}|j
|�}|��}|��}|jjD] }|j|vr|qtt||jt||j��|jr�|�|�r�|�|�qt|jjD]}|�|�r�|�|�q�|jj|j_dS)aU
        Reload field values from the database.

        By default, the reloading happens from the database this instance was
        loaded from, or by the read router if this instance wasn't loaded from
        any database. The using parameter will override the default.

        Fields can be used to specify which fields to reload. The fields
        should be an iterable of field attnames. If fields is None, then
        all non-deferred fields are reloaded.

        When accessing deferred fields of an instance, the deferred loading
        of the field will call this method.
        N�_prefetched_objects_cacher6css�|]}t|vVqdSr�rrar6r6r9r\x��z(Model.refresh_from_db.<locals>.<genexpr>zRFound "%s" in fields argument. Relations and transforms are not allowed in fields.r�)�hints�r�csg|]
}|j�vr|j�qSr6)r�ra��deferred_fieldsr6r9rP�s
�z)Model.refresh_from_db.<locals>.<listcomp>)rrp�remover�r�rr�r��
db_manager�filterr�r�list�onlyrUr�r�r�r��is_relation�	is_cached�delete_cached_value�related_objectsr�r�)	r8�usingr|�prefetched_objects_cacher�r�db_instance_qs�db_instance�non_loaded_fieldsr6r r9�refresh_from_db_sN
���


�

�zModel.refresh_from_dbcCs:z|j�|�}Wntyt||�YSwt||j�S)a�
        Return the value of the field name for this instance. If the field is
        a foreign key, return the id value instead of the object. If there's
        no Field object with this name on the model, return the model
        attribute's value.

        Used to serialize a field's value (in the serializer, or form output,
        for example). Normally, you would just access the attribute directly
        and not use this method.
        )rUr�rrpr�)r8�
field_namer�r6r6r9�serializable_value�s�zModel.serializable_valueFc
Cs$|jdd�|ptj|j|d�}|r|s|rtd��|��}|durZ|s&dSt|�}t�}|jj	D]}|j
sH|�|j�|j|j
krH|�|j
�q1|�|�}|rYtdd�|���n-|s�|r�||jjkr�t�}|jj	D]}|j
s{t|d�s{|�|j
�qk|�|�}	|	r�t|	�}|j||||d	�dS)
aa
        Save the current instance. Override this in a subclass if you want to
        control the saving process.

        The 'force_insert' and 'force_update' parameters can be used to insist
        that the "save" must be an SQL insert or update (or equivalent for
        non-SQL backends), respectively. Normally, they should not be set.
        �save)�operation_name�r�z6Cannot force both insert and updating in model saving.Nz_The following fields do not exist in this model, are m2m fields, or are non-concrete fields: %sr��through)r+�force_insert�force_update�
update_fields)� _prepare_related_fields_for_saver�db_for_writer�r�r�	frozensetr�rUr��primary_keyr�rAr��
differencer�r�r�rI�	save_base)
r8r7r8r+r9r!r�r��non_model_fields�
loaded_fieldsr6r6r9r3�sH
�
���	�

�z
Model.saveTc	Cs|p	tj|j|d�}|r|s|rJ�|dus|sJ�|j}}|jjr'|jj}|j}|js7tj|||||d�|j	rBt
j|dd�}	nt
j|d�}	|	�d}
|sV|�
|||�}
|�|||p]|
|||�}Wd�n1slwY||j_d|j_|js�tj||||||d�dSdS)av
        Handle the parts of saving which should be done only once per save,
        yet need to be done in raw saves, too. This includes some sanity
        checks and signal sending.

        The 'raw' argument is telling save_base not to save any parent
        models and not to do any changes to the values before save. This
        is used by fixture loading.
        r5N)r�r��rawr+r9F)r+�	savepoint�r+)r�r��createdr9rBr+)rr;r�rUrvr}rfr,r�r�r�atomic�mark_for_rollback_on_error�
_save_parents�_save_tabler�r�r�r*)r8rBr7r8r+r9r��originr��context_manager�parent_inserted�updatedr6r6r9r?�s@
�
��	
��zModel.save_basec
Cs�|j}d}|j��D]Q\}}|r/t||jjj�dur/t||j�dur/t||jjjt||j��|j|||d�}|j||||d�}	|	sDd}|r[t||j|�	|j��|�
|�r[|�|�q
|S)z3Save all the parents of cls using values from self.FN)r�r+r9)r�r+r9r7T)rUr�rorpr�r�r�rHrIrr(r))
r8r�r+r9r��insertedr�r�rLrMr6r6r9rHs&�

�zModel._save_parentscs�|j�dd��jD�}�r�fdd�|D�}����}|dur-�j���}t��jj|�|du}	|	s;|s7�r;td��d}
�sQ|sQ�jj	rQ�jj
rQ�jj
turQd}|	r�|s�|j�
|�}��fdd�|D�}�ph|}
��||||�|
�}
|r{|
s{td	���r�|
s�td
��|
s�jr��j}|���}|j�
|�jdi|��jtttd�td�t�d
�td��d�d�_�j}|	s��fdd�|D�}�j}��|j|||��}|r�t|d|�D]\}}t�|j|�q�|
S)zp
        Do the heavy-lifting involved in saving. Update or insert the data
        for a single table.
        cSsg|]}|js|�qSr6�r=rar6r6r9rP=rkz%Model._save_table.<locals>.<listcomp>cs$g|]}|j�vs|j�vr|�qSr6)rAr�ra)r9r6r9rP@s�Nz5Cannot force an update in save() with no primary key.FTcs.g|]}|d�rt�|j�n|��d�f�qSr�)rpr�r,ra)rBr8r6r9rPWs&�z&Forced update did not affect any rows.z0Save with update_fields did not affect any rows.�_order�)�output_fieldr)�_order__maxrScsg|]	}|�jur|�qSr6)�
auto_fieldra)r�r6r9rPnrQr6)rU�local_concrete_fieldsrr��get_pk_value_on_saver�r�r�r�r��defaultrr�r+�
_do_updaterr��get_filter_kwargs_for_objectr$�	aggregater#rrrrrP�db_returning_fields�
_do_insertr�)r8rBr�r7r8r+r9�non_pks�pk_val�pk_setrM�base_qsr��
forced_updater��filter_argsr|�returning_fields�resultsrJr6)r�rBr8r9r9rI6sp
������
���zModel._save_tablecCsX|j|d�}|s|dup|��S|jjr%|s%|��o$|�|�dkp$|��S|�|�dkS)z�
        Try to update the model. Return True if the model was updated (if an
        update query was done and a matching row was found in the DB).
        rNr)r$�existsrU�select_on_save�_update)r8r`r+r^r�r9ra�filteredr6r6r9rXws�zModel._do_updatecCs|j|g||||d�S)z�
        Do an INSERT. If returning_fields is defined then this method should
        return the newly created data for the model.
        )r|rcr+rB)�_insert)r8r�r+r|rcrBr6r6r9r\�s�zModel._do_insertcCs�|jjD]O}|jrS|�|�rSt||jd�}|sq|jdur0|jjs'|j�	|�t
d||jf��t||j�|jvrAt
||j|j�t||jj�t||j�krS|�	|�qdS)NzH%s() prohibited to prevent data loss due to unsaved related object '%s'.)rUr�r'r(rprAr�r��multipler)r�r��empty_valuesr�r)r8r4r�r�r6r6r9r:�s&
��
��z&Model._prepare_related_fields_for_savecCsZ|p	tj|j|d�}|jdusJd|jj|jjjf��t|d�}|j|g|d�|�	�S)Nr5zC%s object can't be deleted because its %s attribute is set to None.rD)�keep_parents)
rr;r�r�rUrr�r�collect�delete)r8r+rl�	collectorr6r6r9rn�s��
zModel.deletecCs2t||j�}tt|j��}t|�t|�|�dd�S)NT)�strings_only)rpr��dictr/�flatchoicesr.r�)r8r�rJ�choices_dictr6r6r9�_get_FIELD_display�szModel._get_FIELD_displayc	Ks�|jstd��|rdnd}|rdnd}t||j�}tdid|j|f|i��}|tdi|j|d||ji��B}|jj�|j	j
�jdi|���|��d||jfd	|�}z|d
WSt
yk|�d|jjj��w)
Nz8get_next/get_previous cannot be used on unsaved objects.�gt�lt��-�%s__%szpk__%sz%s%sz%spkrz!%s matching query does not exist.r6)r�r�rpr�r'rAr�r�r+r�r�r$�order_byr�rWrUr)	r8r�r�r��op�order�param�q�qsr6r6r9�_get_next_or_previous_by_FIELD�s"$�
�z$Model._get_next_or_previous_by_FIELDc	Cs�d|}t||�sR|r
dnd}|rdnd}|jj}|�|�}|jjjdi|��jdid||jj�d�jdi|jjj	|ji��i���
|�dd���}t|||�t
||�S)	Nz__%s_order_cacherurvrPz-_orderz
_order__%srQr6)rIrUr�rYr�r�r$r�r�rArzr�r�rp)r8r��	cachenamer{r|�order_fieldrbr�r6r6r9r��s"

����
z$Model._get_next_or_previous_in_ordercCs(|jdurtd|��t||j��j�S)Nz9Unsaved model instance %r cannot be used in an ORM query.)r�r�rpr��get_related_fieldr�)r8r�r6r6r9�prepare_database_save�s
zModel.prepare_database_savecCr4)aI
        Hook for doing any extra model-wide validation after clean() has been
        called on every field by self.clean_fields. Any ValidationError raised
        by this method will not be associated with a particular field; it will
        have a special-case association with the field defined by NON_FIELD_ERRORS.
        Nr6r7r6r6r9�clean�szModel.cleancCsX|j|d�\}}|�|�}|�|�}|��D]
\}}|�|g��|�q|r*t|��dS)zh
        Check unique constraints on the model and raise ValidationError if any
        failed.
        ��excludeN)�_get_unique_checks�_perform_unique_checks�_perform_date_checksro�
setdefault�extendr)r8r��
unique_checks�date_checks�errors�date_errors�k�vr6r6r9�validate_unique�s

�zModel.validate_uniquecs��durg�g}|j|jjfg}|j|jjfg}|j��D]}|jjr,|�||jjf�|jjr9|�||jjf�q|D]\}}|D]}t�fdd�|D��sX|�|t|�f�qBq<|D]\}}	|	D]}
t�fdd�|
jD��sx|�||
jf�qbq\g}|j|jj	fg}|j��D]}|�||jj	f�q�|D]R\}}
|
D]K}|j
}|�vr�q�|jr�|�||ff�|jr�|j�vr�|�|d||jf�|j
r�|j
�vr�|�|d||j
f�|jr�|j�vr�|�|d||jf�q�q�||fS)a{
        Return a list of checks to perform. Since validate_unique() could be
        called from a ModelForm, some fields may have been excluded; we can't
        perform a unique check on a model that is missing fields involved
        in that check. Fields that did not validate should also be excluded,
        but they need to be passed in via the exclude argument.
        Nc3��|]}|�vVqdSr�r6�rNrAr�r6r9r\&rz+Model._get_unique_checks.<locals>.<genexpr>c3r�r�r6r�r�r6r9r\,r�date�year�month)r�rU�unique_together�total_unique_constraints�get_parent_listr
r�rur|ryrA�unique�unique_for_date�unique_for_year�unique_for_month)r8r�r��unique_togethers�constraints�parent_class�model_classr��check�model_constraints�
constraintr��fields_with_classr|rbrAr6r�r9r�sZ
��������zModel._get_unique_checkscCs�i}|D]v\}}i}|D])}|j�|�}t||j�}|dus&|dkr'tjjr'q|jr/|jj	s/q||t
|�<qt|�t|�kr?q|jj
di|��}	|�|j�}
|jj	s\|
dur\|	j|
d�}	|	��rzt|�dkrk|d}nt}|�|g��|�||��q|S)NrwrrQrr6)rUr�rpr�r�features�!interprets_empty_strings_as_nullsr=r�r��strr�r�r$rr�rerr�r
�unique_error_message)r8r�r�r��unique_check�
lookup_kwargsr1rb�lookup_valuer�model_class_pk�keyr6r6r9r�Hs2
�zModel._perform_unique_checksc
Cs�i}|D]i\}}}}i}t||�}|durq|dkr0|j|d|<|j|d|<|j|d|<nt||�|d||f<t||�||<|jjdi|��}	|jjs[|jdur[|	j	|jd�}	|	�
�rm|�|g��|�
|||��q|S)Nr�z%s__dayz	%s__monthz%s__yearryrr6)rp�dayr�r�r�r$r�r�r�r�rer�r
�date_error_message)
r8r�r�r��lookup_typer��
unique_forr�r�rr6r6r9r�us*
��zModel._perform_date_checksc
CsL|j}|�|�}t|jdd|t|j�||t|j�|t|�|�j�d�d�S)Nr�)r�r�r�r��field_label�
date_field�date_field_label��message�code�params)rUr�r�error_messagesr0�verbose_name)r8r�r1r�r�r�r6r6r9r��s
��zModel.date_error_messagecs�|j�||t�j�|d�}t|�dkr+��|d�}t|j�|d<t|jdd|d�S�fdd�|D�}t|td	��|d
<ttd�d|d�S)
N)r�r�r�r�rQrr�r�r�csg|]
}t��|�j��qSr6)r0r�r�ra�r�r6r9rP��z.Model.unique_error_message.<locals>.<listcomp>�and�field_labelsz9%(model_name)s with this %(field_labels)s already exists.r�)	rUr0r�r�r�rr�r1�_)r8r�r�r�r�r�r6r�r9r��s*���zModel.unique_error_messagec
Csi}|dur	g}nt|�}z|j|d�Wnty,}z|�|�}WYd}~nd}~wwz|��WntyJ}z|�|�}WYd}~nd}~ww|r|D]}|tkr^||vr^|�|�qOz|j|d�Wnty~}z|�|�}WYd}~nd}~ww|r�t|��dS)z�
        Call clean_fields(), clean(), and validate_unique() on the model.
        Raise a ValidationError for any errors that occur.
        Nr�)r%�clean_fieldsr�update_error_dictr�rr
r�)r8r�r�r��erAr6r6r9�
full_clean�s<����
����zModel.full_cleancCs�|durg}i}|jjD]<}|j|vrqt||j�}|jr#||jvr#qz
t||j|�||��Wqt	yH}z|j
||j<WYd}~qd}~ww|rOt	|��dS)z
        Clean all fields and raise a ValidationError containing a dict
        of all validation errors if any occur.
        N)rUr|rArpr��blankrkr�r�r�
error_list)r8r�r�rb�	raw_valuer�r6r6r9r��s$
���zModel.clean_fieldscKs�g|���|���|jdi|���}|jjsu|�d�pg}|g|jdi|���|���|�|��7}g|�	��|�
��|���|���|�
��R}|�|�|sW|�|���|g|���|���|�|��|���|�|��|���7}|S)N�	databasesr6)�_check_swappable�_check_model�_check_managersrUrwr��
_check_fields�$_check_m2m_through_same_relationship�_check_long_column_names�_check_id_field�_check_field_name_clashes�#_check_model_name_db_lookup_clashes�3_check_property_name_related_field_accessor_clashes�_check_single_primary_keyr��_check_column_name_clashes�_check_index_together�_check_unique_together�_check_indexes�_check_ordering�_check_constraints�_check_default_pk)r�r�r�r��clash_errorsr6r6r9r��sL$��������
������	zModel.checkcCsz|jjs;|jjjr;t|jjt�r|jjjjs;t�	d�s;|jj
r;|jj
js;tj
dtj�d�d|jj
jj�d�|dd�gSgS)N�DEFAULT_AUTO_FIELDzPAuto-created primary key used when not defining a primary key type, by default 'z'.z0Configure the DEFAULT_AUTO_FIELD setting or the zh.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.zmodels.W042��hintr��id)rUrTr�rfrMr r�rgr�
is_overriddenr��!_is_default_auto_field_overriddenr�Warningr�r�r?r�r6r6r9r�s4���
��	�
�
�
���zModel._check_default_pkc
Cs�g}|jjrLz
t�|jj�W|Sty(|�tjd|jjdd��Y|St	yK|jj�
d�\}}|�tjd|jj||fdd��Y|Sw|S)z"Check if the swapped model exists.z-'%s' is not of the form 'app_label.app_name'.zmodels.E001�r��.zF'%s' references '%s.%s', which has not been installed, or is abstract.zmodels.E002)rUrwr�	get_modelr�r
r�Error�	swappable�LookupError�split)r�r�rVr�r6r6r9r�>s6�
���
����	�zModel._check_swappablecCs:g}|jjr|jjs|jjr|�tjd|jdd��|S)Nz'Proxy model '%s' contains model fields.zmodels.E017r�)rUrvryrzr
rr�r=�r�r�r6r6r9r�Ys��zModel._check_modelcKs,g}|jjD]
}|�|jdi|���q|S)zPerform all manager checks.Nr6)rUr�r�r�)r�r�r�r�r6r6r9r�fszModel._check_managerscKsTg}|jjD]
}|�|jdi|���q|jjD]}|�|jdd|i|���q|S)zPerform all field checks.�
from_modelNr6)rUryr�r�rz)r�r�r�r�r6r6r9r�nszModel._check_fieldscCs�g}g}|jj}dd�|D�}dd�|D�}|D])}|jj||jj|jjf}||vr<|�tjd|jjjj	|dd��q|�|�q|S)zL Check if no relationship model is used by more than one m2m field.
        cs�"�|]}t|jjt�r|VqdSr�)rMr�r�rLrar6r6r9r\��� z=Model._check_m2m_through_same_relationship.<locals>.<genexpr>csr�r�)rMr�r6rLrar6r6r9r\�r�zWThe model has two identical many-to-many relations through the intermediate model '%s'.zmodels.E003�r�r�)
rUrzr�r�r6�through_fieldsr
rr�rs)r�r��seen_intermediary_signaturesr|rb�	signaturer6r6r9r�xs&
���
z*Model._check_m2m_through_same_relationshipcsH�fdd��jjD�}|r"|djs"�jjjdkr"tjd�dd�gSgS)z%Check if `id` field is a primary key.cs&g|]}|jdkr|�jjkr|�qSr�)rArUr�rar�r6r9rP�s&z)Model._check_id_field.<locals>.<listcomp>rr�zP'id' can only be used as a field name if the field also sets 'primary_key=True'.zmodels.E004r�)rUryr=r�rArr�)r�r|r6r�r9r��s��	zModel._check_id_fieldc
CsNg}i}|j��D]:}|jjD]3}|�|j�p|�|j�pd}|r8|�tjd|j|j	j|j|j	jf|dd��|||j<|||j<qq	|j��D]}|j�
�D]}||vr[|||j<qPqI|jjD]C}|�|j�pp|�|j�ppd}|jdko�|o�|jdko�|j	|k}|r�|s�|�tjd|j|j|j	jf|dd��|||j<|||j<qa|S)z2Forbid field shadowing in multi-table inheritance.NzYThe field '%s' from parent model '%s' clashes with the field '%s' from parent model '%s'.zmodels.E005r�r�z;The field '%s' clashes with the field '%s' from model '%s'.zmodels.E006)rUr�ryr�rAr�r
rr�r��
get_fields)r�r��used_fieldsr�rb�clash�id_conflictr6r6r9r��sV

����
�
��"����

zModel._check_field_name_clashesc	Cs`g}g}|jjD]%}|��\}}|r(||vr(|�tjd|j|fd|dd��q|�|�q|S)Nz>Field '%s' has column name '%s' that is used by another field.z$Specify a 'db_column' for the field.zmodels.E007r�)rUry�get_attname_columnr
rr�rA)r��used_column_namesr�rbr��column_namer6r6r9r��s"���
z Model._check_column_name_clashescCsbg}|j}|�d�s|�d�r|�tjd||dd��|St|vr/|�tjd||dd��|S)Nr�zgThe model name '%s' cannot start or end with an underscore as it collides with the query lookup syntax.zmodels.E023r�zbThe model name '%s' cannot contain double underscores as it collides with the query lookup syntax.zmodels.E024)r=�
startswith�endswithr
rr�r)r�r�r�r6r6r9r��s0�������z)Model._check_model_name_db_lookup_clashescCsTg}|jj}dd�|jjdd�D�}|D]}||vr'|�tjd||dd��q|S)Ncss(�|]}|jr|jdur|��VqdSr�)r'�
related_model�get_attnamerar6r6r9r\s��
��zLModel._check_property_name_related_field_accessor_clashes.<locals>.<genexpr>F��reversez8The property '%s' clashes with a related field accessor.zmodels.E025r�)rUr��_get_fieldsr
rr�)r�r�r��related_field_accessors�accessorr6r6r9r�s$�����z9Model._check_property_name_related_field_accessor_clashescCs8g}tdd�|jjD��dkr|�tjd|dd��|S)Ncss�|]}|jrdVqdS)rQNrOrar6r6r9r\*r�z2Model._check_single_primary_key.<locals>.<genexpr>rQzBThe model cannot have more than one field with 'primary_key=True'.zmodels.E026r�)�sumrUryr
rr�r�r6r6r9r�'s��zModel._check_single_primary_keycC�tt|jjttf�stjd|dd�gStdd�|jjD��r&tjd|dd�gSg}|jjD]}|�|�	|d��q,|S)	z+Check the value of "index_together" option.z)'index_together' must be a list or tuple.zmodels.E008r�cs� �|]}t|ttf�VqdSr��rMrur%�rNr|r6r6r9r\A��z.Model._check_index_together.<locals>.<genexpr>z6All 'index_together' elements must be lists or tuples.zmodels.E009�index_together)
rMrUr
rur%rr�r�r��_check_local_fields�r�r�r|r6r6r9r�5�$����	zModel._check_index_togethercCr)	z,Check the value of "unique_together" option.z*'unique_together' must be a list or tuple.zmodels.E010r�csrr�rrr6r6r9r\\r	z/Model._check_unique_together.<locals>.<genexpr>z7All 'unique_together' elements must be lists or tuples.zmodels.E011r�)
rMrUr�rur%rr�r�r�rrr6r6r9r�Pr
zModel._check_unique_togetherc		Cs�g}t�}|jjD]M}|jddks|jd��r'|�tjd|j|dd��t|j�|j	kr@|�tjd|j|j	f|dd��|j
rV|jD]}|�dd	�|�
|�D��qFq	|D]y}t�||�sbqYt|}|jjs�d
|jjvs�tdd	�|jjD��r�|�tjd|jd
|dd��|jjs�d|jjvs�tdd	�|jjD��r�|�tjd|jd|dd��|jjs�d|jjvs�tdd	�|jjD��r�|�tjd|jd|dd��qYdd�|jjD�}|dd�|jjD�7}||7}|�|�|d��|S)z/Check fields, names, and conditions of indexes.rr�z@The index name '%s' cannot start with an underscore or a number.zmodels.E033r�z8The index name '%s' cannot be longer than %d characters.zmodels.E034css�|]}|dVqdS)rNr6)rN�refr6r6r9r\�s�
�z'Model._check_indexes.<locals>.<genexpr>�supports_partial_indexescss�|]}|jduVqdSr�)�	condition�rNr�r6r6r9r\�r�z,%s does not support indexes with conditions.zLConditions will be ignored. Silence this warning if you don't care about it.zmodels.W037r��supports_covering_indexescsr�r���includerr6r6r9r\�r�z1%s does not support indexes with non-key columns.zQNon-key columns will be ignored. Silence this warning if you don't care about it.zmodels.W040�supports_expression_indexescsr�r�)�contains_expressionsrr6r6r9r\�r�z+%s does not support indexes on expressions.zKAn index won't be created. Silence this warning if you don't care about it.zmodels.W043cSs g|]}|jD]\}}|�qqSr6)�
fields_orders)rNr�r�r�r6r6r9rP�s z(Model._check_indexes.<locals>.<listcomp>cSsg|]
}|jD]}|�qqSr6r)rNr�rr6r6r9rP�r�r�)r�rUr�rA�isdigitr
rr�r��max_name_lengthr�expressionsr��_get_expr_referencesr�allow_migrate_modelrr�r�required_db_featuresr�r��display_namerrr�r)	r�r�r��
referencesr��
expressionr�rr|r6r6r9r�ks����
���


�������
�����
������zModel._check_indexescCs�ddlm}i}|jjdd�D]}|||j<t|d�r |||j<qg}|D]R}z||}WntyE|�t	j
d||f|dd��Yq%wt|j|j
�r^|�t	j
d	|||f|d
d��q%||jjvrw|�t	j
d|||jjfd|d
d��q%|S)Nr)�modelsFr�r�z*'%s' refers to the nonexistent field '%s'.zmodels.E012r�zV'%s' refers to a ManyToManyField '%s', but ManyToManyFields are not permitted in '%s'.zmodels.E013z;'%s' refers to field '%s' which is not local to model '%s'.z4This issue may be caused by multi-table inheritance.zmodels.E016r�)�	django.dbr!rUrrArIr�r�r
rr�rMr��
ManyToManyRelryr)r�r|�optionr!�forward_fields_mapr�r�r1r6r6r9r�s\


���������
����	zModel._check_local_fieldscCs�|jjr
tjd|dd�gS|jjs|jjsgSt|jjttf�s)tjd|dd�gSg}|jj}dd�|D�}dd�|D�}g}g}|D]}t	|vrO|�
|�qC|�
|�qC|}|D]W}|}d	}|�t	�D]K}	z|	d
krp|jj}n|j�
|	�}|jr�|��djj}nd	}Wqdttfy�|d	us�|�|	�d	ur�|�|	�d	ur�|�
tjd||d
d��YqdwqYdd�|D�}g}
|j}tt�dd�t|j|j�D���}|
�||�|
D]}
|�
tjd|
|d
d��q�|S)ze
        Check "ordering" option -- is it a list of strings and do all fields
        exist?
        z?'ordering' and 'order_with_respect_to' cannot be used together.zmodels.E021r�zQ'ordering' must be a tuple or list (even if you want to order by only one field).zmodels.E014css&�|]}t|t�r|dkr|VqdS)�?N)rMr�rar6r6r9r\s�$z(Model._check_ordering.<locals>.<genexpr>css*�|]}|�d�r|dd�n|VqdS)rxrQN)r�rar6r6r9r\s�(Nr����zJ'ordering' refers to the nonexistent field, related field, or lookup '%s'.zmodels.E015cSsh|]}|dkr|�qSrr6rar6r6r9rcBsz(Model._check_ordering.<locals>.<setcomp>css4�|]}|jr
|jr|j|jfn|j��fVqdSr�)rf�concreterAr�r��related_query_namerar6r6r9r\Js
�"�
�)rU�_ordering_clashrr�r�r^rMr%rurr
r�r�r�r'�
get_path_info�to_optsr�rr��
get_transform�
get_lookupr�r�
from_iterabler|r*r�)r�r�r|�_fields�related_fieldsrbr��_cls�fld�part�invalid_fieldsr��valid_fields�
invalid_fieldr6r6r9r��s�����
�������
����zModel._check_orderingc

CsX|sgSg}d}d}|D],}t�||�sqt|}|j��}|dus&|jjr'q|dur0|}|}q||kr8|}|}q|dur?|S|jjD](}|�	�\}	}
|j
durk|
durkt|
�|krk|�t
jd|
||fd|dd��qC|jjD]9}t|jjt�rzqp|jjjjD](}|�	�\}	}|j
dur�|dur�t|�|kr�|�t
jd|||fd|dd��q�qp|S)	z�
        Check that any auto-generated column names are shorter than the limits
        for each database in which the model will be created.
        Nz\Autogenerated column name too long for field "%s". Maximum length is "%s" for database "%s".z/Set the column name manually using 'db_column'.zmodels.E018r�z`Autogenerated column name too long for M2M field "%s". Maximum length is "%s" for database "%s".z\Use 'through' to create a separate model for M2M and then set column_name using 'db_column'.zmodels.E019)rrr�opsrr��truncates_namesrUryr��	db_columnr�r
rr�rzrMr�r6r�)
r�r�r��allowed_len�db_aliasr�rrrbr�r��m2m�rel_namer6r6r9r�\sl
����������zModel._check_long_column_namesccs��t|t�r0|jD]$}t|t�r%|\}}t|�t��V|�|�EdHq	|�|�EdHq	dSt|t�r@t|j�t��VdSt	|d�rT|�
�D]}|�|�EdHqIdSdS)N�get_source_expressions)rMr'�childrenrur�rrr&rArIr?)r��expr�child�lookuprJ�src_exprr6r6r9r�s �


�

�zModel._get_expr_referencesc
Cs�g}|D�]n}t�||�sqt|}|jjs6d|jjvs6tdd�|jjD��r6|�	t
jd|jd|dd��|jj
sZd|jjvsZtd	d�|jjD��rZ|�	t
jd
|jd|dd��|jjs~d|jjvs~td
d�|jjD��r~|�	t
jd|jd|dd��|jjs�d|jjvs�tdd�|jjD��r�|�	t
jd|jd|dd��tt�dd�|jjD���}t�}|jjD]?}t|t�r�|jj
s�d|jjvr�t|jt�r�|�|�|j��q�t|t�r�|jjs�d|jjvr�t|jt�r�|�|�|j��q�|D]p^}}	|dk�r|�|�|	�sq�z |dk�r|jj}
n|j�|�}
|
j�r(|
j�s(|
j �r*Wq�Wn
t!�y5Yq�w|	d}t"|
d��rit"|
d��ri|
�#|�du�ri|
�$|�du�ri|�	t
j%dt&�'|g|	�|dd��q�|�(|�)|d��q|S)N� supports_table_check_constraintscss�|]}t|t�VqdSr�)rMr�rNr�r6r6r9r\�s
��
�z+Model._check_constraints.<locals>.<genexpr>z&%s does not support check constraints.zOA constraint won't be created. Silence this warning if you don't care about it.zmodels.W027r�rcs�$�|]
}t|t�o
|jduVqdSr�)rMrrrFr6r6r9r\��
��
�z7%s does not support unique constraints with conditions.zmodels.W036�&supports_deferrable_unique_constraintscsrGr�)rMr�
deferrablerFr6r6r9r\�rHz2%s does not support deferrable unique constraints.zmodels.W038rcss �|]}t|t�o|jVqdSr�)rMrrrFr6r6r9r\�s
��
�z<%s does not support unique constraints with non-key columns.zmodels.W039css,�|]}t|t�rg|j�|j�RVqdSr�)rMrr|rrFr6r6r9r\	s�
�
�r�rr-r.z.'constraints' refers to the joined field '%s'.zmodels.E041r�r�)*rrrr�rErUrr�r�r
rr�rrrIrr�rr/rMrrr'r�rrr�r�r�r�r'�many_to_many�one_to_manyrrIr-r.r�rr�r�r)r�r�r�r�rr|rr�r1�lookupsr��first_lookupr6r6r9r��s�
�����������
������
������
�
�
��
�
��



��������zModel._check_constraintsr�)NN)FFNN)FFFNN)FNFFNNr�)NT)@r=r>r?r��classmethodr�r:r<rrr
rrrrr�r�rr0r2r3�alters_datar?rHrIrXr\r:rnrtr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rr�rRr6r6r�r9r��s�e




	=
�8
�1
�A

"
	
:-

$
 




	


8






X
1
e
J
r�)�	metaclasscsV|durt}�jj}|�|�}�j�|�jdi|����fdd�t|�D�dg�dS)Ncsg|]
\}}�||d��qS))r�rPr6)rNr|r���ordered_objr6r9rPJs�z$method_set_order.<locals>.<listcomp>rPr6)	r
rUr��get_forward_related_filterr�r#r$�bulk_update�	enumerate)r8rS�id_listr+�	order_wrtrbr6rRr9�method_set_orderEs
"��rYcCs8|jj}|�|�}|jjj}|jjdi|��j|dd�S)NT)�flatr6)rUr�rTr�rAr�r$�values_list)r8rSrXrb�pk_namer6r6r9�method_get_orderOs

r]cCs<t|d|j��tt|��t|d|j��tt|��dS)Nzget_%s_orderzset_%s_order)r�r=�lowerrr]rY)r�r�r6r6r9r�Vs��r�cCs$t|t�rtj|�}n|}|�|�S)z7Used to unpickle Model subclasses with deferred fields.)rMrurr�rm)�model_idr�r6r6r9rgs

rTr�)YrhrGr�	functoolsr�	itertoolsrr�django.appsr�django.confr�django.corer�django.core.exceptionsrrr	r
rrr"r
rrrrrr�django.db.modelsrrrrr�django.db.models.constantsr�django.db.models.constraintsrr�django.db.models.deletionrr�django.db.models.fields.relatedrr r!r"�django.db.models.functionsr#�django.db.models.managerr$�django.db.models.optionsr%�django.db.models.queryr&r'�django.db.models.signalsr(r)r*r+r,�django.db.models.utilsr-�django.utils.encodingr.�django.utils.hashabler/�django.utils.textr0r1�django.utils.translationr2r�r3r�rErKr@rLr�r�r�rYr]r�r�__safe_for_unpickle__r6r6r6r9�<module>sl $;
>



https://t.me/RX1948 - 2025