civic government data • Have that App use the same code for API endpoints as well as rendered templates • Have that app let anyone read, but only authorized users write
installed and project is set up 2. Try to build the model in votes/models.py 3. Add votes to installed_apps in civicapi/seXngs.py 4. python manage.py migrate 5. (extra - see it in admin) https://docs.djangoproject.com/en/2.0/ref/models/fields/ google: django model field reference
add rest_framework to the Django app 3. Try to make the ModelSerializer for Vote in the votes app 4. write a test to verify the serialized data http://www.django-rest-framework.org/api-guide/serializers/#modelserializer
to views 2. add the view to urls.py at /votes/ 3. python manage.py runserver 4. open a browser, browse to localhost:8000 5. play around, try to create some votes 6. (opHonal: write a test for the view) http://www.django-rest-framework.org/api-guide/generic-views/#examples
1), ('subject', 'More apps should be built in Django!'), ('vote_taken', '2018-04-14T19:51:09Z'), ('ayes', 100), ('nays', 0)]),…])]) {'count': 3, 'next': None, 'previous': None, 'results': [{'id': 1, 'subject': 'More apps should be built in Django!', 'vote_taken': '2018-04-14T19:51:09Z', 'ayes': 100, 'nays': 0},...]}
1), ('subject', 'More apps should be built in Django!'), ('vote_taken', '2018-04-14T19:51:09Z'), ('ayes', 100), ('nays', 0)]),…])]) <ul> <li><a href=“/votes/1/"> More apps should be built in Django! - 100/0 on 2018-04-14T19:51:09Z </a></li> … </ul>
to votes 2. add a vote_list.html template 3. add the TemplateHTMLRenderer to VoteList’s renderer_classes, along with JSONRenderer and BrowsableAPIRenderer 4. point the template_name to “vote_list.html" 5. Create votes/templates/vote_list.html 6. Browse to /votes/ and see the list. http://www.django-rest-framework.org/api-guide/renderers/#templatehtmlrenderer
using generics.RetrieveUpdateDestroyAPIView 2. Don’t forget the right renderers! 3. add that view to urls.py 4. add a vote.html template 5. point the template_name to “vote.html" 6. Wire up the links in “vote_list.html” 7. Browse to /votes/ and see the list, make sure the links are clickable. http://www.django-rest-framework.org/tutorial/3-class-based-views/#using-generic-class- based-views
view and VoteDetail view 2. Browse to /votes/ try adding a vote 3. Open an anonymous browser window, try doing the same thing 4. (opHonal: add some tests for the authed and non- authed requests) http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/#adding- required-permissions-to-views
captures renderer classes, queryset, serializer_class, and permission classes 2. Make sure the get_renderers snippet is defined in the mixin 3. Add the mixin to both view classes, remove the duplicate code from the views 4. Browse the api and make sure things sHll work. 5. Run tests and make sure things sHll work
VoteList and VoteDetail views 2. Pay special akenHon to edge cases with authenHcaHon and renderer type 3. Any more tests you can think of? 4. (opHonal: add ability to edit votes from VoteDetail)