
    >Tf                     8    d dl mZmZmZ d dlmZ dZd ZddZdS )	    )CountOuterRefSubquery)Coalesce)count_relateddict_to_filter_paramsc           
      0   t           | j        j        di |t          d          i                                                    |                              t          d                                        d                    }t          |d          S )zI
    Return a Subquery suitable for annotating a child object count.
    pk*)cr   r    )	r   objectsfilterr   order_byvaluesannotater   r   )modelfieldsubquerys      4/var/www/html/netbox-4.1.3/netbox/utilities/query.pyr   r   
   s      	
 	
htnn%	
 	

(**VV
 

(Cjj  
 

&++ H Ha        c                     i }|                                  D ]K\  }}||z   }t          |t                    r'|                    t	          ||dz                        F|||<   L|S )a  
    Translate a dictionary of attributes to a nested set of parameters suitable for QuerySet filtering. For example:

        {
            "name": "Foo",
            "rack": {
                "facility_id": "R101"
            }
        }

    Becomes:

        {
            "name": "Foo",
            "rack__facility_id": "R101"
        }

    And can be employed as filter parameters:

        Device.objects.filter(**dict_to_filter(attrs_dict))
    __)items
isinstancedictupdater   )dprefixparamskeyvalks         r   r   r      ss    , FGGII  SSLc4   	MM/QX>>????F1IIMr   N)r   )	django.db.modelsr   r   r   django.db.models.functionsr   __all__r   r   r   r   r   <module>r(      si    6 6 6 6 6 6 6 6 6 6 / / / / / /! ! !"     r   