
    si                     ^    d dl mZ d dlmZ d dlmZ d dlmZ  G d dej                        Z	y)    )ValidationError)models)Q)	Nominatimc                   
    e Zd Z ej                         Z ej                         Z ej                         Z ej                  ddej                  dd      Z ej                  d      Z fdZ fdZ G d	 d
      Z xZS )
GeoFencingzbase.Companygeo_fencingT)related_name	on_deleteblanknullF)defaultc                    | j                   ct        j                  j                  d      }| j                  r|j                  | j                        }|j                         rt        d      t        d      }	 |j                  | j                  | j                  fd      }|st        d      	 t        | 9         S # t        $ r}t        d	|       d }~ww xY w)
NT)company_id__isnull)pkz/Only one GeoFencing can have a null company_id.geo_checker_unique)
user_agent)exactly_onezInvalid location coordinates.zGeolocation error: )
company_idr   objectsfilterr   excludeexistsr   r   reverselatitude	longitude	Exceptionsuperclean)selfqs
geolocatorlocatione	__class__s        5/var/www/python-projects/worksol/geofencing/models.pyr   zGeoFencing.clean   s    ??"##**d*CBwwZZ477Z+yy{%&WXX+

	=!))/T * H %&EFF 
 w}  	=!$7s";<<	=s   >6C 	CCCc                 D    | j                          t        |   |i | y )N)
full_cleanr   save)r    argskwargsr%   s      r&   r)   zGeoFencing.save*   s    d%f%    c                   J    e Zd Z ej                  dgd ed             gZy)GeoFencing.Metar   *unique_company_id_when_not_null_geofencingN)r   )fieldsname	condition)__name__
__module____qualname__r   UniqueConstraintr   constraints r,   r&   Metar.   .   s,    #F##$~A--
r,   r9   )r3   r4   r5   r   
FloatFieldr   r   IntegerFieldradius_in_metersOneToOneFieldCASCADEr   BooleanFieldstartr   r)   r9   __classcell__)r%   s   @r&   r   r      s     v  "H!!!#I*v**,%%%"..J  F.E,&
 
r,   r   N)
django.core.exceptionsr   	django.dbr   django.db.modelsr   geopy.geocodersr   Modelr   r8   r,   r&   <module>rG      s!    2   %.
 .
r,   