swsnu / swppfall2021

Learning Software Engineering By Building Web Services
28 stars 19 forks source link

[hw4] question regarding jsonResponse format for GET request #125

Open yeppin opened 3 years ago

yeppin commented 3 years ago

I have a question regarding the format of jsonResponse as the result of http GET request. Is it okay if I got a jsonResponse like below for the GET /api/article/, when I only had this one object? [{'id': 1, 'title': 'I Love SWPP!', 'content': 'Believe it or not', 'author_id': 1}]

I wondered if I should change 'author_id' key into 'author'.

ttoru96 commented 3 years ago

Yes, please follow the given example at hw4 specification and change 'author_id' key into 'author'.

from .models import Article, Comment

new_user = User.objects.create_user(username='swpp', password='iluvswpp')  # Django default user model
new_article = Article(title='I Love SWPP!', content='Believe it or not', author=new_user)
new_article.save()
new_comment = Comment(article=new_article, content='Comment!', author=new_user)
new_comment.save()