Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of issues with your code above.</p> <p>First, yes you can expose any custom manager to anything, regardless if you are using it tastypie or not. AdvertManager you defined above can be accessed through Advert.objects only if you have replaced it default manager with your own version.</p> <p>Second, the way you want to expose tastypie filtering on AdvertResource is orthogonal on how filtering actually works.</p> <p>All filters are applied as practically ORM filters in the form <code>&lt;field_name&gt;__&lt;filter_name&gt;=&lt;value_or_values&gt;</code>. Since in your example you are using <code>box=&lt;number&gt;,&lt;number&gt;,...,&lt;number&gt;</code> tastypie explodes that into <code>box__exact=...</code> and tries to find <code>box</code> field in AdvertResource and fails as expected.</p> <p>If your advert has a field called <code>location</code> you could add <code>withinbox</code> as a filter for that field and filter by: <code>location__withinbox=&lt;values&gt;</code>.</p> <p>If you want to keep your original approach, you would have to parse the box filter yourself from request.GET dictionary and then pass them to your own overridden version of <code>obj_get</code> and <code>obj_get_list</code> in AdvertResource.</p> <p>Finally, when extending <code>build_filters</code> you are only making a mapping between Tastypie filter and an ORM filter. In your example you are returning objects as a filter; instead simply define it as:</p> <pre><code>{ 'withinbox' : 'point__within' } </code></pre> <p>and convert the list of values into <code>Polygon</code> within <code>apply_filters</code> before it is handed off to the actual filter method.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload