Answer the question
In order to leave comments, you need to log in
How can I get an object by ForeignKey?
serializers.serialize('json', Post.objects.filter(category=category_id))
{
"success": true,
"message": "Successful",
"data": [
{
"model": "blog.post",
"pk": 1,
"fields": {
"title": "Смерть перед жизнью",
"category": 2,
"content": "<p>fgasdf ewfwef qwefweqf wef wefwe</p>",
"audio": "media/audio/2017/04/11/5.17.23_PM.ogg",
"video": "media/video/2017/04/11/7M6ilfg.mp4",
"author": 1,
"preview": "media/preview/2017/04/12/default.jpg",
"view_count": 0,
"pub_date": "2017-04-11T11:10:38Z"
}
}
}
Answer the question
In order to leave comments, you need to log in
You forgot to add a couple of arguments to the serialize call:
serializers.serialize('json', Post.objects.filter(category=category_id),
use_natural_foreign_keys=True, use_natural_primary_keys=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question