Advertisement
jjmaestro

Tastypie Related fields example

May 17th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. ## models.py
  2. class UserProfile(models.Model):
  3.     username = models.CharField(max_length=100, blank=True, null=True)
  4.     email = models.EmailField()
  5.     friends = models.ManyToManyField('self')
  6.  
  7. ## resources.py
  8. class UserProfileResource(ModelResource):
  9.     friends = fields.ToManyField('self', 'friends')
  10.  
  11.     class Meta:
  12.         queryset = UserProfile.objects.all()
  13.         filtering = {
  14.             'friends': ['exact'],
  15.         }
  16.  
  17. ## Queries:
  18.   - friends=1           ## Works
  19.   - friends__friends=1  ## Fails unless I use ALL_WITH_RELATIONS in filtering
  20.  
  21. ## Tastypie lines concerned:
  22. ## https://github.com/toastdriven/django-tastypie/blob/master/tastypie/resources.py#L1625-1626
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement