mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 01:47:59 +03:00 
			
		
		
		
	update some examples
This commit is contained in:
		
							parent
							
								
									7dcb851c7f
								
							
						
					
					
						commit
						ff6e78323f
					
				
							
								
								
									
										27
									
								
								examples/blogpost/resources.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								examples/blogpost/resources.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					from django.core.urlresolvers import reverse
 | 
				
			||||||
 | 
					from djangorestframework.resources import ModelResource
 | 
				
			||||||
 | 
					from blogpost.models import BlogPost, Comment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class BlogPostResource(ModelResource):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    A Blog Post has a *title* and *content*, and can be associated with zero or more comments.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    model = BlogPost
 | 
				
			||||||
 | 
					    fields = ('created', 'title', 'slug', 'content', 'url', 'comments')
 | 
				
			||||||
 | 
					    ordering = ('-created',)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def comments(self, instance):
 | 
				
			||||||
 | 
					        return reverse('comments', kwargs={'blogpost': instance.key}) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CommentResource(ModelResource):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    A Comment is associated with a given Blog Post and has a *username* and *comment*, and optionally a *rating*. 
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    model = Comment
 | 
				
			||||||
 | 
					    fields = ('username', 'comment', 'created', 'rating', 'url', 'blogpost')
 | 
				
			||||||
 | 
					    ordering = ('-created',)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def blogpost(self, instance):
 | 
				
			||||||
 | 
					        return reverse('blog-post', kwargs={'key': instance.blogpost.key}) 
 | 
				
			||||||
							
								
								
									
										7
									
								
								examples/modelresourceexample/resources.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								examples/modelresourceexample/resources.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					from djangorestframework.resources import ModelResource
 | 
				
			||||||
 | 
					from modelresourceexample.models import MyModel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MyModelResource(ModelResource):
 | 
				
			||||||
 | 
					    model = MyModel
 | 
				
			||||||
 | 
					    fields = ('foo', 'bar', 'baz', 'url')
 | 
				
			||||||
 | 
					    ordering = ('created',)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user