-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_code.txt
21 lines (17 loc) · 1.11 KB
/
shell_code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
>>> from api_basic.models import Article
>>> from api_basic.serializers import ArticleSerializer
>>> from rest_framework.renderers import JSONRenderer
>>> from rest_framework.parsers import JSONParser
>>> a = Article(title='Article Title', author='akash', email='[email protected]')
>>> a.save()
>>> a = Article(title='Article Title2', author='ram', email='[email protected]')
>>> a.save()
>>> serializer = ArticleSerializer(a)
>>> serializer.data
{'title': 'Article Title2', 'author': 'ram', 'email': '[email protected]', 'date': '2020-07-09T03:50:37.578511Z'}
>>> content = JSONRenderer().render(serializer.data)
>>> content
b'{"title":"Article Title2","author":"ram","email":"[email protected]","date":"2020-07-09T03:50:37.578511Z"}'
>>> serializer = ArticleSerializer(Article.objects.all(),many=True)
>>> serializer.data
[OrderedDict([('title', 'Article Title'), ('author', 'akash'), ('email', '[email protected]'), ('date', '2020-07-09T03:46:46.591321Z')]), OrderedDict([('title', 'Article Title2'), ('author', 'ram'), ('email', '[email protected]'), ('date', '2020-07-09T03:50:37.578511Z')])]