title: Django Tastypie - Filtering ToManyField resource with URL parameter
body: <p>I am working on implementing an API for my Django (v1.5) application using Tastypie. I would like to be able to filter/limit the related resources I get when the parent resource.</p>
  
  <p>Here are my (simplified) models:</p>
  
  <pre><code># myapp/models.py
  class User(models.Model):
      number = models.IntegerField()
      device_id = models.CharField(verbose_name="Device ID", max_length=255)
      timezone = models.CharField(max_length=255, blank=True)
  
      def data(self, limit=0):
          result = Data.objects.filter(patient_id = self.id).order_by('-datetime').values('datetime', 'value')
          if limit != 0:
              result = result[:limit]
          return result
  
  class Data(models.Model):
      user = models.ForeignKey(User)
      datetime = models.DateTimeField()
      value = models.IntegerField()
  </code></pre>
  
  <p>My resources:</p>
  
  <pre><code># api/resources.py
  class DataResource(ModelResource):
      class Meta:
          queryset = Data.objects.all()
          resource_name = 'cgm'
          fields = ['value', 'datetime']
          serializer = Serializer(formats=['json', 'xml'])
          filtering = {
              'datetime': ('gte', 'lte'),
          }
          include_resource_uri = False
  
      def dehydrate(self, bundle):
          bundle.data['timestamp'] = calendar.timegm(bundle.data['datetime'].utctimetuple())
          return bundle
  
  
  class UserResource(ModelResource):
  
      data = fields.ToManyField(DataResource, attribute=lambda bundle: Data.objects.filter(patient_id=bundle.obj.id), full=True, related_name='data', null=True)
  
      class Meta:
          queryset = User.objects.all().order_by('number')
          resource_name = 'user'
          fields = ['number', 'timezone', 'device_id'],
          serializer = Serializer(formats=['json', 'xml'])
          filtering = {
              'data': ALL_WITH_RELATIONS,
          }
  </code></pre>
  
  <p>I would like to be able to filter the <em>Data</em> resources by <em>'datetime'</em> inside the <em>User</em> resource using an URL parameter, e.g.:</p>
  
  <pre><code>127.0.0.1:8000/api/v1/user/1/?format=json&amp;datetime__gte=2013-11-14%2012:00:00 
  </code></pre>
  
  <p>or </p>
  
  <pre><code>127.0.0.1:8000/api/v1/user/1/?format=json&amp;data__datetime__gte=2013-11-14%2012:00:00
  </code></pre>
  
  <p>to get the User's <em>number</em>, <em>timezone</em>, <em>device id</em> and <em>Data</em> list filtered with the given <em>datetime</em>.</p>
  
  <p>I don't want to have to query the <em>Data</em> resources separately to filter them, I want the whole thing bundled within the <em>User</em> resource.
  Is there a way to implement a filter applied to the nested resource using the framework?</p>
  
  <p>Thanks for your time, I'll appreciate any suggestion!</p>