o 3a@sPddlmZddlmZdddZeddZ  ddd Zdd d Zd dZdS)) namedtuple)RECURSIVE_RELATIONSHIP_CONSTANTNcCst|tr9|tkr|dus|durtd||fSd|vr+|dd\}}||fS|dur3td||fS|jj|jjfS)z Turn a model class or model reference string and return a model tuple. app_label and model_name are used to resolve the scope of recursive and unscoped model relationship. NzMapp_label and model_name must be provided to resolve recursive relationships..zCapp_label must be provided to resolve unscoped model relationships.) isinstancestrr TypeErrorsplitlower_meta app_label model_name)modelr r rG/usr/lib/python3/dist-packages/django/db/migrations/operations/utils.pyresolve_relations   rFieldReferencez to throughc Cs|j}|sdSd}d}t|jg|R|kr7t|dd}|dus3|dus3d|vr/|dus3|js3||vr7||f}t|dd} | r\t| g|R|kr\|j} |dusX| dusX|| vr\|| f}|sb|sbdSt||S)at Return either False or a FieldReference if `field` references provided context. False positives can be returned if `reference_field_name` is provided without `reference_field` because of the introspection limitation it incurs. This should not be an issue when this function is used to determine whether or not an optimization can take place. FN to_fieldsthrough) remote_fieldrrgetattr primary_keythrough_fieldsr) model_tuplefieldreference_model_tuplereference_field_namereference_fieldr references_toreferences_throughrrrrrrfield_references$s,   r rccsT|jD]!\}}|jD]\}}t|||g|R}|r&||||fVqqdS)z Generator of (model_state, name, field, reference) referencing provided context. If field_tuple is provided only references to this particular field of model_tuple will be generated. N)modelsitemsfieldsr )stater field_tuplestate_model_tuple model_statenamer referencerrrget_referencesUsr*cCstt|||dduS)z?Return whether `field_tuple` is referenced by any state models.N)nextr*)r$rr%rrrfield_is_referenceddsr,)NN)r) collectionsrdjango.db.models.fields.relatedrrrr r*r,rrrrs    1