Skip to content

Commit c501f23

Browse files
API docs
1 parent 2a56705 commit c501f23

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

snippets/models.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
class Snippet(models.Model):
1414
created = models.DateTimeField(auto_now_add=True)
15-
title = models.CharField(max_length=100, blank=True, default='')
16-
code = models.TextField()
17-
linenos = models.BooleanField(default=False)
15+
title = models.CharField(max_length=100, blank=True, default='', help_text='A descriptive title for the snippet.')
16+
code = models.TextField(help_text='The code sample to highlight.')
17+
linenos = models.BooleanField(default=False, verbose_name='Line numbers', help_text='`True` if line numbers should be included.')
1818
language = models.CharField(choices=LANGUAGE_CHOICES,
1919
default='python',
20-
max_length=100)
20+
max_length=100,
21+
help_text='Programming language.')
2122
style = models.CharField(choices=STYLE_CHOICES,
2223
default='friendly',
23-
max_length=100)
24+
max_length=100,
25+
help_text='Highlighting style.')
2426
owner = models.ForeignKey('auth.User', related_name='snippets')
2527
highlighted = models.TextField()
2628

snippets/views.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ def highlight(self, request, *args, **kwargs):
3434

3535
def perform_create(self, serializer):
3636
serializer.save(owner=self.request.user)
37-
37+
3838
class UserViewSet(viewsets.ReadOnlyModelViewSet):
3939
"""
40-
This endpoint presents the users in the system.
40+
list:
41+
42+
Return all the user instances.
43+
44+
retrieve:
4145
42-
As you can see, the collection of snippet instances owned by a user are
43-
serialized using a hyperlinked representation.
46+
Return the given user instance.
4447
"""
4548
queryset = User.objects.all()
4649
serializer_class = UserSerializer

tutorial/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
DEBUG = True
44
TEMPLATE_DEBUG = DEBUG
5-
5+
ALLOWED_HOSTS = ['*']
66
ADMINS = (
77
# ('Your Name', 'your_email@example.com'),
88
)

tutorial/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from snippets import views
22
from django.conf.urls import patterns, url, include
3+
from rest_framework.documentation import get_docs_view
34
from rest_framework.routers import DefaultRouter
45

6+
57
router = DefaultRouter()
68
router.register(r'snippets', views.SnippetViewSet)
79
router.register(r'users', views.UserViewSet)
810

11+
912
urlpatterns = patterns('',
1013
url(r'^', include(router.urls)),
11-
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
14+
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
15+
url(r'^docs/', get_docs_view(title='Pastebin API')),
1216
)

0 commit comments

Comments
 (0)