I think we could factor out a lot of similar code. What about this?

```python
class ProducerFactory(object):                                                                      
    """                                                                                             
    Class that generates list and stat producer functions.                                          
                                                                                                    
    Example usage::                                                                                 
                                                                                                    
        device_producer_factory = ProducerFactory(models.Device, 'description__icontains')          
        device_list_producer = device_producer_factory.list()                                       
        device_stat_producer = device_producer_factory.stat()                                       
                                                                                                    
    """                                                                                             
    def __init__(self, model, filter_target):                                                       
        """                                                                                         
        Initialize a new producer.                                                                  
                                                                                                    
        Args:                                                                                       
            model:                                                                                  
                The model class that you want to quer.                                              
            query_filter:                                                                           
                The target for the filter query, for example                                        
                ``description__icontains``.                                                         
                                                                                                    
        """                                                                                         
        self.model = model                                                                          
        self.filter_target = filter_target                                                          
                                                                                                    
    def list(self):                                                                                 
        """                                                                                         
        Return a list producer function.                                                            
        """                                                                                         
        def _func(from_idx, to_idx, filter_query):                                                  
            qs = self.model.objects.all()                                                           
            if filter_query:                                                                        
                kwargs = {self.filter_target: filter_query}                                         
                qs = qs.filter(**kwargs)                                                            
            return qs[from_idx:to_idx]                                                              
        return _func                                                                                
                                                                                                    
    def stat(self):                                                                                 
        """                                                                                                            
        Return a list producer function.                                                            
        """                                                                                         
        def _func(page_size, filter_query):                                                         
            qs = self.model.objects.all()                                                           
            if filter_query:                                                                        
                kwargs = {self.filter_target: filter_query}                                         
                qs = qs.filter(**kwargs)                                                            
            return math.ceil(qs.count() / page_size)                                                
        return _func                                                                                
```

You can then instantiate the class in this file:

```python
device_producer_factory = ProducerFactory(models.Device, 'description__icontains')
```

...and in the ajax module, simply call the methods directly:

```python
'device_list': paging_functions.device_producer_factory.list()
```