This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # ... | |
| from tastypie.resources import ModelResource, fields | |
| # ... | |
| class TodoItemResource(ModelResource): | |
| todo_list = fields.ForeignKey(TodoListResource, 'todo_list') | |
| class Meta: | |
| authentication = SessionAuthentication() | |
| authorization = AuthorizationByList() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "meta":{ | |
| "limit":20, | |
| "next":null, | |
| "offset":0, | |
| "previous":null, | |
| "total_count":1 | |
| }, | |
| "objects":[ | |
| { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class TodoItemResource(ModelResource): | |
| class Meta: | |
| authentication = SessionAuthentication() | |
| authorization = AuthorizationByList() | |
| queryset = TodoItem.objects.all() | |
| resource_name = 'item' | |
| filtering = { | |
| 'text': ('icontains',) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "item_count":2, | |
| "list_count":1 | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class TodoListResource(ModelResource): | |
| def prepend_urls(self): | |
| return [ | |
| url(r"^(?P<resource_name>%s)/stats%s$" % | |
| (self._meta.resource_name, trailing_slash()), | |
| self.wrap_view('stats'), name="api_list_stats"), | |
| ] | |
| def dehydrate(self, bundle): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class TodoListResource(ModelResource): | |
| def dehydrate(self, bundle): | |
| items = bundle.obj.items.all() | |
| bundle.data['item_count'] = items.count() | |
| bundle.data['items'] = [i.to_dict() for i in items] | |
| return bundle | |
| class Meta: | |
| authentication = SessionAuthentication() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class TodoItem(models.Model): | |
| text = models.TextField('Item Text') | |
| todo_list = models.ForeignKey(TodoList, related_name='items') | |
| def to_dict(self): | |
| return {'text': self.text, 'id': self.pk} | |
| def __unicode__(self): | |
| return self.text[:50] + ' ' + unicode(self.todo_list) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class TodoListResource(ModelResource): | |
| class Meta: | |
| authentication = SessionAuthentication() | |
| authorization = AuthorizationByUser() | |
| queryset = TodoList.objects.all() | |
| resource_name = 'list' |