a
    T%?jã  ã                   @   s*   d dl mZ dd„ ZG dd„ dejƒZdS )é    )Ú
migrationsc                 C   sv   |   dd¡}tƒ }g }|j ¡  d¡D ]4}|j|j|jf}||v rP| |j	¡ q&| 
|¡ q&|rr|jj|d� ¡  dS )z:Remove duplicate registrations keeping only the first one.ÚeventsÚRegistrationÚid)Zid__inN)Ú	get_modelÚsetÚobjectsÚallÚorder_byÚtournament_idÚclubÚteamÚappendr   ÚaddÚfilterÚdelete)ÚappsÚschema_editorr   ÚseenZduplicates_to_deleteÚregÚkey© r   úm/var/www/test.vcks.de/backend/backend/events/migrations/0006_remove_duplicate_registrations_and_add_unique.pyÚremove_duplicates   s    r   c                   @   s,   e Zd ZdgZe e¡ejddhd�gZdS )Ú	Migration)r   Ú0005_event_registration_mailÚregistration)Ú
tournamentr   r   )ÚnameÚunique_togetherN)	Ú__name__Ú
__module__Ú__qualname__Údependenciesr   Ú	RunPythonr   ÚAlterUniqueTogetherÚ
operationsr   r   r   r   r      s   ÿþþr   N)Ú	django.dbr   r   r   r   r   r   r   Ú<module>   s   