
0_c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z m Z m Z m Z d  d	 l m Z d  d
 l m Z m  Z  d  d l! m" Z" m# Z# m$ Z$ m% Z% d  d l& m' Z' d  d l( m) Z) d  d l* m+ Z+ d  d l, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 d  d l2 m3 Z3 d  d l4 m5 Z5 d  d l6 m7 Z7 d  d l8 m9 Z9 m: Z: m; Z; d  d l< m= Z= d  d l> m? Z? d  d l@ mA ZA mB ZB d  d lC mD ZE d  d lF mG ZG e; d eH f d     Y ZI eI   ZJ eK d  ZL d eM f d     YZN d eH f d     YZO d  e5 jP eN  f d!     YZQ eK d"  ZR d#   ZS d$   ZT d%   ZU eV eU _W d&   ZX d S('   i(   t   unicode_literalsN(   t   chain(   t   apps(   t   settings(   t   checks(   t   NON_FIELD_ERRORSt   FieldDoesNotExistt
   FieldErrort   MultipleObjectsReturnedt   ObjectDoesNotExistt   ValidationError(   t   DEFAULT_DB_ALIASt   DJANGO_VERSION_PICKLE_KEYt   DatabaseErrort
   connectiont   connectionst   routert   transaction(   t
   LOOKUP_SEP(   t   CASCADEt	   Collector(   t   ForeignObjectRelt   OneToOneFieldt   lazy_related_operationt   resolve_relation(   t   Manager(   t   Options(   t   Q(   t   class_preparedt	   post_initt	   post_savet   pre_initt   pre_save(   t   make_model_tuple(   t   six(   t   RemovedInDjango20Warning(   t	   force_strt
   force_textt   python_2_unicode_compatible(   t   curry(   t   zip(   t   capfirstt   get_text_list(   t   ugettext_lazy(   t   get_versiont   Deferredc           B  s   e  Z d    Z d   Z RS(   c         C  s
   t  d  S(   Nu   <Deferred field>(   t   str(   t   self(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __repr__-   s    c         C  s
   t  d  S(   Nu   <Deferred field>(   R.   (   R/   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __str__0   s    (   t   __name__t
   __module__R0   R1   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR-   +   s   	c           s[   i | d 6}   d k	 rK    f d   } d   } | | d <| | d <n  t  | |  S(   u  
    Create exception subclass. Used by ModelBase below.

    If 'attached_to' is supplied, the exception will be created in a way that
    allows it to be pickled, assuming the returned exception class will be added
    as an attribute to the 'attached_to' class.
    u
   __module__c           s   t     f |  j f S(   N(   t   unpickle_inner_exceptiont   args(   R/   (   t   attached_tot   name(    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt
   __reduce__A   s    c         S  s   | |  _  d  S(   N(   R5   (   R/   R5   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __setstate__F   s    u
   __reduce__u   __setstate__N(   t   Nonet   type(   R7   t   parentst   moduleR6   t
   class_dictR8   R9   (    (   R6   R7   s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   subclass_exception7   s    	
t	   ModelBasec           B  sP   e  Z d  Z d   Z d   Z d   Z d   Z e d    Z e d    Z	 RS(   u#   
    Metaclass for all models.
    c   $      C  s  t  t |   j } g  | D] } t | t  r | ^ q } | sS | |  | | |  S| j d  } i | d 6} | j d d   }	 |	 d  k	 r |	 | d <n  | |  | | |  }
 | j d d   } t | d t  } | s t |
 d d   } n | } t |
 d d   } d  } t j	 |  } t | d d   d  k rm| d  k ra| sjt
 d | | f   qjqm| j } n  |
 j d t | |   | sf|
 j d t t d  t d	   | D  pt f | d
 |
  |
 j d t t d  t d   | D  pt f | d
 |
  | rf| j rft | d  s?| j |
 j _ n  t | d  sc| j |
 j _ qcqfn  |
 j j } | r| r| j rt d | | j f   n  x* | j   D] \ } } |
 j | |  qWt |
 j j |
 j j |
 j j  } d   | D } | rd  } x g  | D] } t | d  r| ^ qD]w } | j j rp| j j  r9t d |   qpq9n  | d  k r| } q9| j j! | j j! k	 r9t d |   q9q9W| d  k rt d |   n  |
 j j" |  | j j! |
 j _! n |
 |
 j _! i  } x t# |
 g |  D] } t | d  s9qn  | |
 k rX| j j rXqn  xK | j j D]= } t | t$  ret% |
 | j& j'  } | | t( |  <qeqeWqWt)   } x|
 j*   D]} | | k st | d  r| t) | j+ j,    O} qn  | j j | j j } | j j sIxO | D]G } | j- | k rat. d | j- | | j/ f   q*| j0 | j-  q*W| j j! } t( |  } | | k r| | } n | s0d | j j1 } t$ | d t2 d | d t3 d t3 } | | k rt. d | | | j/ f   n  t |
 |  s6|
 j | |  q6n d  } | |
 j j4 | <n | j j4 j5   }  x | D] } | j- | k rb| j- |
 j+ k rb| j- | k rbt5 j6 |  }! |
 j | j- |!  | j7 rx6 |  j   D]% \ } }" | |" k r|! |  | <qqWqqbqbW|
 j j4 j8 |   xp | j j D]b } | j- | k ri| j j st. d | j- | | j/ f   qq#|
 j | j- t5 j6 |   q#WqWg  |
 j j9 D] }# t5 j6 |#  ^ q|
 j _9 | rt | _ | |
 _: |
 S|
 j;   |
 j j j< |
 j j= |
  |
 S(   Nu
   __module__u   __classcell__u   Metau   abstractu   _metau	   app_labeluf   Model class %s.%s doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.u   DoesNotExistc         s  s4   |  ]* } t  | d   r | j j r | j Vq d S(   u   _metaN(   t   hasattrt   _metat   abstractt   DoesNotExist(   t   .0t   x(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>   s    R6   u   MultipleObjectsReturnedc         s  s4   |  ]* } t  | d   r | j j r | j Vq d S(   u   _metaN(   RA   RB   RC   R   (   RE   RF   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>   s    u   orderingu   get_latest_byu'   %s cannot proxy the swapped model '%s'.c         S  s   h  |  ] } | j   q S(    (   R7   (   RE   t   f(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <setcomp>   s   	 uO   Abstract base class containing model fields not permitted for proxy model '%s'.uA   Proxy model '%s' has more than one non-abstract model base class.u6   Proxy model '%s' has no non-abstract model base class.uR   Local field %r in class %r clashes with field of the same name from base class %r.u   %s_ptrt	   on_deleteR7   t   auto_createdt   parent_linkut   Auto-generated field '%s' in class %r for parent_link to base class %r clashes with declared field of the same name.(>   t   superR@   t   __new__t
   isinstancet   popR:   t   getattrt   FalseR   t   get_containing_app_configt   RuntimeErrort   labelt   add_to_classR   R?   R.   t   tupleR	   R   RC   RA   t   orderingRB   t   get_latest_byt   proxyt   swappedt	   TypeErrort   itemsR   t   local_fieldst   local_many_to_manyt   private_fieldst   fieldst   concrete_modelt   setup_proxyt   reversedR   R   t   remote_fieldt   modelR!   t   sett   mrot   __dict__t   keysR7   R   R2   t   addt
   model_nameR   t   TrueR<   t   copyt   deepcopyt
   one_to_onet   updatet   indexest   Metat   _preparet   register_modelt	   app_label($   t   clsR7   t   basest   attrst	   super_newt   bR<   R=   t	   new_attrst	   classcellt	   new_classt	   attr_metaRC   t   metat	   base_metaRt   t
   app_configt   is_proxyt   obj_namet   objt
   new_fieldst   field_namest   baset   klst   parentt   parent_linkst   fieldt   relatedt   inherited_attributest   parent_fieldst   base_keyt	   attr_namet   base_parentst	   new_fieldRJ   t   idx(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRL   S   s4   (	
	
		/				$.		
c         C  sF   t  j |  r2 t | d  r2 | j |  |  n t |  | |  d  S(   Nu   contribute_to_class(   t   inspectt   isclassRA   t   contribute_to_classt   setattr(   Ru   R7   t   value(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRT   B  s    c         C  s  |  j  } | j |   | j r t |  j d t |  _ t |  j d t |  _ | j j	 r | j } | j	 j
 } t t |  |  q n  |  j d
 k r d |  j d j d   | j D  f |  _ n  t j j | j  } | r t |  d |  n  | j s|  j   r\t d   | j D  r7t d |  j   n  t   } t | _ |  j d |  n  x- |  j  j D] } | j si| j  |   qiqiWt! j" d	 |   d
 S(   uJ   
        Creates some methods once self._meta has been populated.
        t   is_nextu   %s(%s)u   , c         s  s   |  ] } | j  Vq d  S(   N(   R7   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>`  s    u   get_absolute_urlc         s  s   |  ] } | j  d  k Vq d S(   u   objectsN(   R7   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>g  s    uO   Model %s must specify a custom Manager, because it has a field named 'objects'.u   objectst   senderN(#   RB   Rr   t   order_with_respect_toR'   t   _get_next_or_previous_in_orderRk   t   get_next_in_orderRP   t   get_previous_in_orderRc   Rd   R   t   make_foreign_order_accessorst   __doc__R:   R2   t   joinR_   R   t   ABSOLUTE_URL_OVERRIDESt   gett   label_lowerR   t   managerst    _requires_legacy_default_managert   anyt
   ValueErrorR   RI   RT   Rp   R7   t   set_name_with_modelR   t   send(   Ru   t   optst   wrtt   remotet   get_absolute_url_overridet   managert   index(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRr   I  s4    			/			c         C  sH  |  j  } | j r t S| j } x"| j D] } | j } |  | k s\ |  j  j s\ | j  j r) | |  j k	 r | j	 r t
 j d j d |  j d | j d | j d | j j  j d | j d | j j  j  t d  | j | _	 | j   n  Pq) q) W| j s@t
 j d	 j d |  j d | j d | j d | j j  j  t d  n  t Sd  S(
   Nu  Managers from concrete parents will soon qualify as default managers if they appear before any other managers in the MRO. As a result, '{legacy_default_manager}' declared on '{legacy_default_manager_model}' will no longer be the default manager for '{model}' in favor of '{future_default_manager}' declared on '{future_default_manager_model}'. You can redeclare '{legacy_default_manager}' on '{cls}' to keep things the way they are or you can switch to the new behavior right away by setting `Meta.manager_inheritance_from_future` to `True`.Ru   Rd   t   legacy_default_managert   legacy_default_manager_modelt   future_default_managert   future_default_manager_modeli   u  Managers from concrete parents will soon qualify as default managers. As a result, the 'objects' manager won't be created (or recreated) automatically anymore on '{model}' and '{future_default_manager}' declared on '{future_default_manager_model}' will be promoted to default manager. You can declare explicitly `objects = models.Manager()` on '{cls}' to keep things the way they are or you can switch to the new behavior right away by setting `Meta.manager_inheritance_from_future` to `True`.(   RB   t   manager_inheritance_from_futureRP   t   default_managerR   t   _originating_modelRX   RC   t   _default_managert   default_manager_namet   warningst   warnt   formatR2   RS   R7   R#   t   _expire_cacheRI   Rk   (   Ru   R   R   R   t   originating_model(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR   y  s<    									

		
			c         C  s
   |  j  j S(   N(   RB   t   base_manager(   Ru   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   _base_manager  s    c         C  s
   |  j  j S(   N(   RB   R   (   Ru   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     s    (
   R2   R3   R   RL   RT   Rr   R   t   propertyR   R   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR@   O   s   			0	It
   ModelStatec           B  s   e  Z d  Z d d  Z RS(   u,   
    A class for storing instance state
    c         C  s   | |  _  t |  _ d  S(   N(   t   dbRk   t   adding(   R/   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __init__  s    	N(   R2   R3   R   R:   R   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     s   t   Modelc           B  s  e  Z d    Z e d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d1 d	  Z d
   Z e e e  Z d   Z d1 d1 d  Z d   Z e e d1 d1 d  Z e e _ e e e d1 d1 d  Z e e _ d   Z e d1 e e d1 d1 d  Z d   Z d   Z d1 e d  Z e e _ d   Z d   Z d   Z  d   Z! d   Z" d1 d  Z# d1 d  Z$ d   Z% d   Z& d   Z' d   Z( d1 e d   Z) d1 d!  Z* e d"    Z+ e d#    Z, e d$    Z- e d%    Z. e d&    Z/ e d'    Z0 e d(    Z1 e d)    Z2 e d*    Z3 e d+    Z4 e d,    Z5 e d-    Z6 e d.    Z7 e d/    Z8 e d0    Z9 RS(2   c         O  s  |  j  } |  j } t } t } t j d | d | d |  t   |  _ t |  t | j	  k rp t
 d   n  | s t | j	  } x t | |  D]1 \ } }	 | | k r q n  | |  |	 j |  q Wng t | j  } xU t | |  D]D \ } }	 | | k r
q n  | |  |	 j |  | j |	 j d   q Wxi| D]a}	 t }
 |	 j | k rk|	 j d  k rkq;n  | rCt |	 j t  r
y | j |	 j  } t }
 WnG t k
 ry | j |	 j  } Wqt k
 r|	 j   } qXq@X| d  k r@|	 j r@d  } q@qOy | j |	 j  } WqOt k
 r?|	 j   } qOXn |	 j   } |
 rz| | k	 r| |  |	 j |  qq;| | k	 r;| |  |	 j |  q;q;W| rV| j } x~ t |  D]p } yP | | k s| j |  r| | | k	 r| |  | | |  n  | | =n  Wqt t f k
 r+qXqW| rVt  d t! |  d   qVn  t" t# |   j$   t% j d | d |   d  S(   NR   R5   t   kwargsu'   Number of args exceeds number of fieldsu5   '%s' is an invalid keyword argument for this functioni    t   instance(&   t	   __class__RB   R   t   DEFERREDR   R   R   t   _statet   lent   concrete_fieldst
   IndexErrort   iterR(   t   attnameR_   RN   R7   R:   RP   t   columnRM   Rc   R   Rk   t   KeyErrort   get_defaultt   nullt   _property_namesRU   t	   get_fieldt   AttributeErrorR   RZ   t   listRK   R   R   R   (   R/   R5   R   Ru   R   t   _setattrt	   _DEFERREDt   fields_itert   valR   t   is_related_objectt   rel_objt   property_namest   prop(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     sx    		
	 c         C  s   t  |  t  |  j j  k rq t |  } | j   g  |  j j D]' } | j | k rb | j   n t ^ qA } n  |  |   } t | j	 _
 | | j	 _ | S(   N(   R   RB   R   R   t   reverseR   RN   R   RP   R   R   R   (   Ru   R   R   t   valuesRG   t   new(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   from_dbA  s    
=c         C  sM   y t  j |   } Wn t t f k
 r2 d } n Xt d |  j j | f  S(   Nu   [Bad Unicode data]u   <%s: %s>(   R"   t	   text_typet   UnicodeEncodeErrort   UnicodeDecodeErrorR$   R   R2   (   R/   t   u(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR0   L  s
    
c         C  s?   t  j r+ t |  d  r+ t |   j d  St d |  j j  S(   Nu   __unicode__u   utf-8u	   %s object(   R"   t   PY2RA   R%   t   encodeR.   R   R2   (   R/   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR1   S  s    c         C  sa   t  | t  s t S|  j j | j j k r/ t S|  j   } | d  k rQ |  | k S| | j   k S(   N(   RM   R   RP   RB   R`   t   _get_pk_valR:   (   R/   t   othert   my_pk(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __eq__X  s    
c         C  s   |  j  |  S(   N(   R   (   R/   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __ne__b  s    c         C  s1   |  j    d  k r! t d   n  t |  j     S(   Nu8   Model instances without primary key value are unhashable(   R   R:   RZ   t   hash(   R/   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   __hash__e  s    c         C  s>   |  j  } t   | t <|  j j |  j j f } t | f | f S(   N(   Rg   R,   R   RB   Rt   t   object_namet   model_unpickle(   R/   t   datat   class_id(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR8   j  s    	c         C  s   d  } | j t  } | rF t   } | | k rL d | | f } qL n d } | rk t j | t d d n  |  j j |  d  S(   NuQ   Pickled model instance's Django version %s does not match the current version %s.u9   Pickled model instance's Django version is not specified.t
   stackleveli   (	   R:   R   R   R,   R   R   t   RuntimeWarningRg   Ro   (   R/   t   statet   msgt   pickled_versiont   current_version(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR9   p  s    	c         C  s%   | s |  j  } n  t |  | j j  S(   N(   RB   RO   t   pkR   (   R/   R~   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     s    c         C  s   t  |  |  j j j |  S(   N(   R   RB   R   R   (   R/   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   _set_pk_val  s    c           s     f d     j  j D S(   uV   
        Returns a set containing names of deferred fields for this instance.
        c           s+   h  |  ]! } | j    j k r | j   q S(    (   R   Rg   (   RE   RG   (   R/   (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <setcomp>  s   	 (   RB   R   (   R/   (    (   R/   s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   get_deferred_fields  s    c         C  s.  | d k	 rN t |  d k r" d St d   | D  rN t d t   qN n  | d k	 r` | n	 |  j j } |  j j j	 |  j
 d |  j  } |  j   } | d k	 r t |  } | j |   } nI | rg  |  j j D] } | j | k r | j ^ q } | j |   } n  | j   } | j   } x |  j j D] }	 |	 j | k rOq4n  t |  |	 j t | |	 j   |	 j r4|	 j   |  j k r4t |  |	 j    }
 t | |	 j  } |
 d k rd n t |
 |	 j j  } | | k s| d k r| d k r|  j |	 j   =qq4q4W| j j |  j _ d S(   uV  
        Reloads 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.
        i    Nc         s  s   |  ] } t  | k Vq d  S(   N(   R   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>  s    uR   Found "%s" in fields argument. Relations and transforms are not allowed in fields.R   (   R:   R   R   R   R   R   R   R   R   t   usingt   filterR   R   R   t   onlyRB   R   R   R   R   RO   t   is_relationt   get_cache_nameRg   t   target_field(   R/   R   R_   R   t   db_instance_qst   deferred_fieldsRG   t   db_instancet   non_loaded_fieldsR   t   rel_instancet	   local_valt   related_val(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   refresh_from_db  s<    $'$c         C  sD   y |  j  j |  } Wn t k
 r3 t |  |  SXt |  | j  S(   u  
        Returns the value of the field name for this instance. If the field is
        a foreign key, returns the id value, instead of the object. If there's
        no Field object with this name on the model, the model attribute's
        value is returned directly.

        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.
        (   RB   R   R   RO   R   (   R/   t
   field_nameR   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   serializable_value  s
    c      	   C  s}  x |  j  j D] } | j r y t |  | j    Wn t k
 rI q n Xt |  | j d  } | r | j d k r | j	 j
 s t | | j	 j    n  t d | j   q q q W| p t j |  j d |  } | r | s | r t d   n  |  j   } | d k	 rt |  d k r#d St |  } t   } xU |  j  j D]G } | j sE| j | j  | j | j k r| j | j  qqEqEW| j |  }	 |	 rWt d d j |	    qWn | rW| rW| |  j j k rWt   } xA |  j  j D]3 } | j rt | d  r| j | j  qqW| j |  }
 |
 rWt |
  } qWn  |  j d	 | d
 | d | d |  d S(   ub  
        Saves 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.
        uJ   save() prohibited to prevent data loss due to unsaved related object '%s'.R   u6   Cannot force both insert and updating in model saving.i    NuE   The following fields do not exist in this model or are m2m fields: %su   , u   throughR   t   force_insertt   force_updatet   update_fields(   RB   R   R  RO   R  R   R7   R:   R   Rc   t   multiplet   delattrR   R   t   db_for_writeR   R   R   t	   frozensetRe   R_   t   primary_keyRi   R   t
   differenceR   R   R   RA   t	   save_base(   R/   R  R  R   R  R   R   R  R   t   non_model_fieldst   loaded_fields(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   save  sR    				c   
      C  sp  | p t  j |  j d |  } | o- | p- | s7 t  | d k s[ t |  d k s[ t  |  j } } | j j r | j j } n  | j } | j	 s t
 j d | d |  d | d | d |  n  t j d | d t  ? | s |  j | | |  n  |  j | | | | | |  }	 Wd QX| |  j _ t |  j _ | j	 slt j d | d |  d	 |	 d | d | d |  n  d S(
   uw  
        Handles 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.
        R   i    R   t   rawR   R  t	   savepointNt   created(   R   R  R   t   AssertionErrorR:   R   RB   RX   R`   RI   R    R   R   t   atomicRP   t   _save_parentst   _save_tableR   R   R   R   (
   R/   R  R  R  R   R  Ru   t   originR~   t   updated(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  +  s*    $			
$		c         C  s  | j  } x| j j   D] \ } } | r t |  | j  j j  d k r t |  | j  d k	 r t |  | j  j j t |  | j   n  |  j d | d | d |  |  j	 d | d | d |  | r t |  | j |  j
 | j    | j   } t |  |  rt |  |  qq q Wd S(   uF   
        Saves all the parents of cls using values from self.
        Ru   R   R  N(   RB   R<   R[   RO   R   R   R:   R   R   R!  R   R  RA   R  (   R/   Ru   R   R  R~   R   R   t
   cache_name(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR   U  s    	$(c         C  s  | j  } g  | j D] } | j s | ^ q }	 | rn g  |	 D]* } | j | k s_ | j | k r; | ^ q; }	 n  |  j |  }
 |
 d k r | j j |   }
 t	 |  | j j |
  n  |
 d k	 } | r | s | r t
 d   n  t } | r| r| j j |  } g  |	 D]9 } | d | r2t |  | j  n | j |  t  f ^ q} | pV| } |  j | | |
 | | |  } | r| rt d   n  | r| rt d   qn  | s| j r| j } | j |   } | j j |  j |   j   } | |  _ n  | j } | s@g  | D] } | | j k	 r| ^ q} n  | j oM| } |  j | j | | | |  } | rt	 |  | j j |  qn  | S(   ut   
        Does the heavy-lifting involved in saving. Updates or inserts the data
        for a single table.
        u5   Cannot force an update in save() with no primary key.u&   Forced update did not affect any rows.u0   Save with update_fields did not affect any rows.N(   RB   t   local_concrete_fieldsR  R7   R   R   R:   R   t   get_pk_value_on_saveR   R   RP   R   R   RO   R    t
   _do_updateR   R   t   get_filter_kwargs_for_objectR   t   countt   _ordert
   auto_fieldt
   _do_insert(   R/   R  Ru   R  R  R   R  R~   RG   t   non_pkst   pk_valt   pk_setR#  t   base_qsR   t   forced_updateR   t   filter_argst   order_valueR_   t	   update_pkt   result(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR!  m  sL    	%-C			!	+c         C  s   | j  d |  } | s. | d k	 p- | j   S|  j j rs | rs | j   rl | j |  d k pk | j   St Sn  | j |  d k S(   u   
        This method will try to update the model. If the model was updated (in
        the sense that an update query was done and a matching row was found
        from the DB) the method will return True.
        R   i    N(   R   R:   t   existsRB   t   select_on_savet   _updateRP   (   R/   R0  R   R.  R   R  R1  t   filtered(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR'    s    c      
   C  s(   | j  |  g d | d | d | d | S(   ux   
        Do an INSERT. If update_pk is defined then this method should return
        the new pk for the model.
        R_   t	   return_idR   R  (   t   _insert(   R/   R   R   R_   R4  R  (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR,    s    c         C  s   | p t  j |  j d |  } |  j   d  k	 sU t d |  j j |  j j j	 f   t
 d |  } | j |  g d | | j   S(   NR   uC   %s object can't be deleted because its %s attribute is set to None.R   t   keep_parents(   R   R  R   R   R:   R  RB   R   R   R   R   t   collectt   delete(   R/   R   R<  t	   collector(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR>    s    c         C  s7   t  |  | j  } t t | j  j | |  d t S(   Nt   strings_only(   RO   R   R%   t   dictt   flatchoicesR   Rk   (   R/   R   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   _get_FIELD_display  s    c   	      K  s&  |  j  s t d   n  | r$ d n d } | r6 d n d } t t |  | j   } t i | d | j | f 6  } | t i | | j 6|  j  d | 6  B} |  j j j	 |  j
 j  j |   j |  j d | | j f d	 |  } y | d
 SWn- t k
 r!|  j d |  j j j   n Xd  S(   Nu8   get_next/get_previous cannot be used on unsaved objects.u   gtu   ltu    u   -u   %s__%su   pk__%su   %s%su   %spki    u!   %s matching query does not exist.(   R   R   R%   RO   R   R   R7   R   R   R   R   R   R   t   order_byR   RD   RB   R   (	   R/   R   R   R   t   opt   ordert   paramt   qt   qs(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   _get_next_or_previous_by_FIELD  s    	 (-c         C  s   d | } t  |  |  s | r% d n d } | r7 d n d } |  j j } | j |   } |  j j j |   j i |  j j j d  j i |  j |  j j j	 6  d | 6  j
 |  d  j   } t |  | |  n  t |  |  S(   Nu   __%s_order_cacheu   gtu   ltu   _orderu   -_orderu
   _order__%si   (   RA   RB   R   R(  R   R   R   R   R   R7   RD  R   R   RO   (   R/   R   t	   cachenameRE  RF  t   order_fieldR2  R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     s    
$c         C  s;   |  j  d  k r" t d |    n  t |  | j j   j  S(   Nu9   Unsaved model instance %r cannot be used in an ORM query.(   R   R:   R   RO   Rc   t   get_related_fieldR   (   R/   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   prepare_database_save  s    c         C  s   d S(   uI  
        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.
        N(    (   R/   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   clean  s    c         C  s   |  j  d |  \ } } |  j |  } |  j |  } x3 | j   D]% \ } } | j | g   j |  qC W| r t |   n  d S(   un   
        Checks unique constraints on the model and raises ``ValidationError``
        if any failed.
        t   excludeN(   t   _get_unique_checkst   _perform_unique_checkst   _perform_date_checksR[   t
   setdefaultt   extendR
   (   R/   RP  t   unique_checkst   date_checkst   errorst   date_errorst   kt   v(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   validate_unique  s    c         C  s<  | d k r g  } n  g  } |  j |  j j f g } x? |  j j   D]. } | j j rC | j | | j j f  qC qC Wx_ | D]W \ } } xH | D]@ } x7 | D] } | | k r Pq q W| j | t |  f  q Wq| Wg  }	 |  j |  j j f g }
 x0 |  j j   D] } |
 j | | j j f  qWx|
 D] \ } } x | D] } | j } | | k rcqBn  | j	 r| j | | f f  n  | j
 r| j
 | k r|	 j | d | | j
 f  n  | j r| j | k r|	 j | d | | j f  n  | j rB| j | k rB|	 j | d | | j f  qBqBWq/W| |	 f S(   u  
        Gather 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.
        u   dateu   yearu   monthN(   R:   R   RB   t   unique_togethert   get_parent_listt   appendRU   R\   R7   t   uniquet   unique_for_datet   unique_for_yeart   unique_for_month(   R/   RP  RV  t   unique_togetherst   parent_classt   model_classR]  t   checkR7   RW  t   fields_with_classR_   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRQ    s>    		 !		'c         C  s{  i  } xn| D]f\ } } i  } x | D] } |  j  j |  } t |  | j  } | d  k s& | d k rz t j j rz q& n  | j r |  j	 j
 r q& n  | | t |  <q& Wt |  t |  k r q n  | j j |   }	 |  j | j   }
 |  j	 j
 r|
 d  k	 r|	 j d |
  }	 n  |	 j   r t |  d k rE| d } n t } | j | g   j |  j | |   q q W| S(   Nu    R   i   i    (   RB   R   RO   R   R:   R   t   featurest!   interprets_empty_strings_as_nullsR  R   R   R.   R   R   R   R   RP  R6  R   RT  R_  t   unique_error_message(   R/   RV  RX  Rf  t   unique_checkt   lookup_kwargsR  RG   t   lookup_valueRI  t   model_class_pkt   key(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRR  G  s0    ,c   
      C  s=  i  } x0| D](\ } } } } i  } t  |  |  } | d  k rF q n  | d k r | j | d | <| j | d | <| j | d | <n t  | |  | d | | f <t  |  |  | | <| j j |   }	 |  j j r |  j	 d  k	 r |	 j
 d |  j	  }	 n  |	 j   r | j | g   j |  j | | |   q q W| S(   Nu   dateu   %s__dayu	   %s__monthu   %s__yearu   %s__%sR   (   RO   R:   t   dayt   montht   yearR   R   R   R   R   RP  R6  RT  R_  t   date_error_message(
   R/   RW  RX  Rf  t   lookup_typeR   t
   unique_forRm  t   dateRI  (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRS  t  s&    c         C  s   |  j  } | j |  } t d | j d d d d i |  d 6t j t | j   d 6| d 6| d 6t j t | j   d	 6| d
 6t j t | j |  j   d 6 S(   Nt   messageu   unique_for_datet   codet   paramsu   modelu
   model_nameu   lookup_typeu   fieldu   field_labelu
   date_fieldu   date_field_label(   RB   R   R
   t   error_messagesR"   R   R)   t   verbose_name(   R/   Ru  R  Rv  R   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRt    s    	c         C  s  | j  } i |  d 6| d 6t j t | j   d 6| d 6} t |  d k r | j | d  } t j t | j   | d <t d | j d	 d
 d	 d |  Sg  | D] } t | j |  j  ^ q } t j t	 | t
 d    | d <t d t
 d  d
 d d |  Sd  S(   Nu   modelu   model_classu
   model_nameu   unique_checki   i    u   field_labelRx  u   uniqueRy  Rz  u   andu   field_labelsu9   %(model_name)s with this %(field_labels)s already exists.u   unique_together(   RB   R"   R   R)   R|  R   R   R
   R{  R*   t   _(   R/   Rf  Rl  R   Rz  R   RG   t   field_labels(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRk    s&    	
+"c         C  s-  i  } | d k r g  } n t |  } y |  j d |  Wn" t k
 r_ } | j |  } n Xy |  j   Wn" t k
 r } | j |  } n X| rx< | j   D]. } | t k r | | k r | j |  q q Wy |  j	 d |  Wqt k
 r} | j |  } qXn  | r)t |   n  d S(   u   
        Calls clean_fields, clean, and validate_unique, on the model,
        and raises a ``ValidationError`` for any errors that occurred.
        RP  N(
   R:   R   t   clean_fieldsR
   t   update_error_dictRO  Rh   R   R_  R\  (   R/   RP  R\  RX  t   eR7   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt
   full_clean  s,    	c         C  s   | d k r g  } n  i  } x |  j j D] } | j | k rC q( n  t |  | j  } | j rs | | j k rs q( n  y# t |  | j | j	 | |    Wq( t
 k
 r } | j | | j <q( Xq( W| r t
 |   n  d S(   u   
        Cleans all fields and raises a ValidationError containing a dict
        of all validation errors if any occur.
        N(   R:   RB   R_   R7   RO   R   t   blankt   empty_valuesR   RO  R
   t
   error_list(   R/   RP  RX  RG   t	   raw_valueR  (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s    	#c         K  s  g  } | j  |  j    | j  |  j    | j  |  j |    |  j j s| j  |  j |    | j  |  j    | j  |  j    |  j	   |  j
   |  j   } | j  |  | s | j  |  j    n  | j  |  j    | j  |  j    | j  |  j    n  | S(   N(   RU  t   _check_swappablet   _check_modelt   _check_managersRB   RY   t   _check_fieldst$   _check_m2m_through_same_relationshipt   _check_long_column_namest   _check_id_fieldt   _check_field_name_clashest#   _check_model_name_db_lookup_clashest   _check_column_name_clashest   _check_index_togethert   _check_unique_togethert   _check_ordering(   Ru   R   RX  t   clash_errors(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyRg    s"    c         C  s   g  } |  j  j r y t j |  j  j  Wq t k
 rb | j t j d |  j  j d d  q t	 k
 r |  j  j j
 d  \ } } | j t j d |  j  j | | f d d  q Xn  | S(   u$    Check if the swapped model exists. u-   '%s' is not of the form 'app_label.app_name'.t   idu   models.E001u   .uF   '%s' references '%s.%s', which has not been installed, or is abstract.u   models.E002(   RB   RY   R   t	   get_modelR   R_  R   t   Errort	   swappablet   LookupErrort   split(   Ru   RX  Rt   Rj   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s"    c         C  sW   g  } |  j  j rS |  j  j s* |  j  j rS | j t j d |  j d d  qS n  | S(   Nu'   Proxy model '%s' contains model fields.R  u   models.E017(   RB   RX   R\   R]   R_  R   R  R2   (   Ru   RX  (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  3  s    c         K  s7   g  } x* |  j  j D] } | j | j |    q W| S(   u    Perform all manager checks. (   RB   R   RU  Rg  (   Ru   R   RX  R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  @  s    c         K  sj   g  } x* |  j  j D] } | j | j |    q Wx0 |  j  j D]" } | j | j d |  |   q@ W| S(   u    Perform all field checks. t
   from_model(   RB   R\   RU  Rg  R]   (   Ru   R   RX  R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  I  s     c         C  s   g  } g  } |  j  j } d   | D } d   | D } xw | D]o } | j j |  | j j f } | | k r | j t j d | j j j  j d |  d d  q? | j |  q? W| S(   uL    Check if no relationship model is used by more than one m2m field.
        c         s  s*   |  ]  } t  | j j t  r | Vq d  S(   N(   RM   Rc   Rd   R@   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>_  s    c         s  s*   |  ]  } t  | j j t  r | Vq d  S(   N(   RM   Rc   t   throughR@   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>b  s    uM   The model has two many-to-many relations through the intermediate model '%s'.R   R  u   models.E003(	   RB   R]   Rc   Rd   R  R_  R   R  RS   (   Ru   RX  t   seen_intermediary_signaturesR_   RG   t	   signature(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  T  s     c           so   t    f d     j j D  } | rg | d j rg   j j j d k rg t j d d   d d g Sg  Sd S(	   u'    Check if `id` field is a primary key. c         3  s6   |  ], } | j  d  k r |   j j k r | Vq d S(   u   idN(   R7   RB   R   (   RE   RG   (   Ru   (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>v  s    i    u   iduP   'id' can only be used as a field name if the field also sets 'primary_key=True'.R   R  u   models.E004N(   R   RB   R\   R  R   R7   R   R  (   Ru   R_   (    (   Ru   s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  s  s    ")
c      	   C  s  g  } i  } x |  j  j   D] } x | j  j D] } | j | j  p\ | j | j  p\ d } | r | j t j	 d | j | j
 j  | j | j
 j  f d |  d d  n  | | | j <| | | j <q/ Wq WxM |  j  j   D]< } x3 | j  j   D]" } | | k r | | | j <q q Wq Wx |  j  j D] } | j | j  pX| j | j  pXd } | j d k o| o| j d k o| j
 |  k } | r| r| j t j	 d | j | j | j
 j  f d | d d  n  | | | j <| | | j <q+W| S(	   u    Ref #17673. uY   The field '%s' from parent model '%s' clashes with the field '%s' from parent model '%s'.R   R  u   models.E005u   idu;   The field '%s' clashes with the field '%s' from model '%s'.u   models.E006N(   RB   R^  R\   R   R7   R   R:   R_  R   R  Rd   t
   get_fields(   Ru   RX  t   used_fieldsR   RG   t   clasht   id_conflict(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s@    **3c      
   C  s   g  } g  } x} |  j  j D]o } | j   \ } } | r{ | | k r{ | j t j d | j | f d d d |  d d  q | j |  q W| S(   Nu>   Field '%s' has column name '%s' that is used by another field.t   hintu$   Specify a 'db_column' for the field.R   R  u   models.E007(   RB   R\   t   get_attname_columnR_  R   R  R7   (   Ru   t   used_column_namesRX  RG   R}  t   column_name(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s    c         C  s   g  } |  j  } | j d  s- | j d  rV | j t j d | d |  d d  n5 t | k r | j t j d | d |  d d  n  | S(   Nu   _ug   The model name '%s' cannot start or end with an underscore as it collides with the query lookup syntax.R   R  u   models.E023ub   The model name '%s' cannot contain double underscores as it collides with the query lookup syntax.u   models.E024(   R2   t
   startswitht   endswithR_  R   R  R   (   Ru   RX  Rj   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s"    	c         C  s   t  |  j j t t f  s7 t j d d |  d d g St d   |  j j D  ro t j d d |  d d g Sg  } x- |  j j D] } | j |  j	 | d   q W| Sd	 S(
   u-    Check the value of "index_together" option. u)   'index_together' must be a list or tuple.R   R  u   models.E008c         s  s%   |  ] } t  | t t f  Vq d  S(   N(   RM   RU   R   (   RE   R_   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>  s    u6   All 'index_together' elements must be lists or tuples.u   models.E009u   index_togetherN(
   RM   RB   t   index_togetherRU   R   R   R  R   RU  t   _check_local_fields(   Ru   RX  R_   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    s    

c         C  s   t  |  j j t t f  s7 t j d d |  d d g St d   |  j j D  ro t j d d |  d d g Sg  } x- |  j j D] } | j |  j	 | d   q W| Sd	 S(
   u.    Check the value of "unique_together" option. u*   'unique_together' must be a list or tuple.R   R  u   models.E010c         s  s%   |  ] } t  | t t f  Vq d  S(   N(   RM   RU   R   (   RE   R_   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>  s    u7   All 'unique_together' elements must be lists or tuples.u   models.E011u   unique_togetherN(
   RM   RB   R]  RU   R   R   R  R   RU  R  (   Ru   RX  R_   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  
  s    

c      
   C  s/  d d l  m } d   |  j j d t  D } g  } x | D] } y | | } Wn= t k
 r | j t j d | | f d |  d d  q< Xt	 | j
 | j  r | j t j d	 | | | f d |  d d
  q< | |  j j k r< | j t j d | | |  j j f d d d |  d d  q< q< W| S(   Ni(   t   modelsc         S  s   i  |  ] } | | j   q S(    (   R7   (   RE   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys
   <dictcomp>,  s   	 R   u+   '%s' refers to the non-existent field '%s'.R   R  u   models.E012uV   '%s' refers to a ManyToManyField '%s', but ManyToManyFields are not permitted in '%s'.u   models.E013u;   '%s' refers to field '%s' which is not local to model '%s'.R  u4   This issue may be caused by multi-table inheritance.u   models.E016(   t	   django.dbR  RB   t   _get_fieldsRP   R   R_  R   R  RM   Rc   t   ManyToManyRelR\   R   (   Ru   R_   t   optionR  t   forward_fields_mapRX  R  R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  %  s:    c         C  sW  |  j  j r( t j d d |  d d g S|  j  j sA |  j  j rE g  St |  j  j t t f  s| t j d d |  d d g Sg  } |  j  j } d   | D } d   | D } d	   | D } d
   | D } g  } |  j  } t	 t
 j d   t
 | j | j  D   } | j | |  x4 | D], } | j t j d | d |  d d  q#W| S(   uU    Check "ordering" option -- is it a list of strings and do all fields
        exist? u?   'ordering' and 'order_with_respect_to' cannot be used together.R   R  u   models.E021uQ   'ordering' must be a tuple or list (even if you want to order by only one field).u   models.E014c         s  s!   |  ] } | d  k r | Vq d S(   u   ?N(    (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>r  s    c         s  s.   |  ]$ } | j  d   r" | d n | Vq d S(   u   -i   N(   R  (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>u  s    c         s  s!   |  ] } t  | k r | Vq d  S(   N(   R   (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>y  s    c         S  s"   h  |  ] } | d  k r |  q S(   u   pk(    (   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <setcomp>}  s   	 c         s  sF   |  ]< } | j  o | j s. | j | j f n | j j   f Vq d  S(   N(   RI   t   concreteR7   R   R   t   related_query_name(   RE   RG   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pys	   <genexpr>  s   u1   'ordering' refers to the non-existent field '%s'.u   models.E015(   RB   t   _ordering_clashR   R  R   RV   RM   R   RU   Re   R   t   from_iterableR_   t   related_objectsRU  R_  (   Ru   RX  R_   t   invalid_fieldsR   t   valid_fieldst   invalid_field(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR  U  s>    

		
c         C  s  g  } d
 } d
 } x t j j   D] } t j | |   s@ q" n  t | } | j j   } | d
 k s" | j	 j
 rw q" q" | d
 k r | } | } q" | | k  r" | } | } q" q" W| d
 k r | Sx |  j j D]} } | j   \ } }	 | j d
 k r |	 d
 k	 r t |	  | k r | j t j d |	 | | f d d d |  d d  q q Wx |  j j D] } t | j j t j  rq\n  x | j j j j D]} }
 |
 j   \ } } |
 j d
 k r| d
 k	 rt |  | k r| j t j d | | | f d d d |  d d	  qqWq\W| S(   u   
        Check that any auto-generated column names are shorter than the limits
        for each database in which the model will be created.
        u\   Autogenerated column name too long for field "%s". Maximum length is "%s" for database "%s".R  u/   Set the column name manually using 'db_column'.R   R  u   models.E018u`   Autogenerated column name too long for M2M field "%s". Maximum length is "%s" for database "%s".u\   Use 'through' to create a separate model for M2M and then set column_name using 'db_column'.u   models.E019N(   R:   R   t	   DATABASESRh   R   t   allow_migrate_modelR   t   opst   max_name_lengthRi  t   truncates_namesRB   R\   R  t	   db_columnR   R_  R   R  R]   RM   Rc   R  R"   t   string_types(   Ru   RX  t   allowed_lent   db_aliasR   R   R  RG   R}  R  t   m2mt   rel_name(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR    sT    
	--N(:   R2   R3   R   t   classmethodR   R0   R1   R   R   R   R8   R9   R:   R   R   R   R   R   R  R  RP   R  Rk   t   alters_dataR  R   R!  R'  R,  R>  RC  RJ  R   RN  RO  R\  RQ  RR  RS  Rt  Rk  R  R  Rg  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     sp   	h			
							4		N	'			3									4	-			$	:0Ac      	   C  s   | d  k r t } n  |  j j } | j |  } t j d | d t  D x< t |  D]. \ } } |  j	 j
 d | |  j d |  qV WWd  QXd  S(   NR   R  R   R*  (   R:   R   RB   R   t   get_forward_related_filterR   R  RP   t	   enumeratet   objectsR   Ro   (   t   ordered_objR/   t   id_listR   t	   order_wrtR2  t   it   j(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   method_set_order  s    	c         C  sI   |  j  j } | j |  } |  j  j j } |  j j |   j | d t S(   Nt   flat(	   RB   R   R  R   R7   R  R   t   values_listRk   (   R  R/   R  R2  t   pk_name(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   method_get_order  s    c         C  sP   t  | d |  j j   t t |    t  | d |  j j   t t |    d  S(   Nu   get_%s_orderu   set_%s_order(   R   R2   t   lowerR'   R  R  (   Rd   t   related_model(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR     s    c         C  s4   t  |  t  r! t j |    } n |  } | j |  S(   uA   
    Used to unpickle Model subclasses with deferred fields.
    (   RM   RU   R   R  RL   (   t   model_idRd   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR   
  s    c         C  s   t  |  |  } | j |  S(   N(   RO   RL   (   t   klasst   exception_namet	   exception(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyR4     s    (Y   t
   __future__R    Rl   R   R   t	   itertoolsR   t   django.appsR   t   django.confR   t   django.coreR   t   django.core.exceptionsR   R   R   R   R	   R
   R  R   R   R   R   R   R   R   t   django.db.models.constantsR   t   django.db.models.deletionR   R   t   django.db.models.fields.relatedR   R   R   R   t   django.db.models.managerR   t   django.db.models.optionsR   t   django.db.models.queryR   t   django.db.models.signalsR   R   R   R   R    t   django.db.models.utilsR!   t   django.utilsR"   t   django.utils.deprecationR#   t   django.utils.encodingR$   R%   R&   t   django.utils.functionalR'   t   django.utils.six.movesR(   t   django.utils.textR)   R*   t   django.utils.translationR+   R}  t   django.utils.versionR,   t   objectR-   R   R:   R?   R;   R@   R   t   with_metaclassR   R  R  R   R   Rk   t   __safe_for_unpickle__R4   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/db/models/base.pyt   <module>   sX   .4"(	 }     				