1👍
✅
give title
category = Category.objects.get(title=title) post_list = category.post_set.all()
return result
1👍
From the category objects you can retrieve the related objects using the automatically created field post_set, if the post model is named Post.
This is a bit tricky to find in the documentation because it is in a dedicated section, see here:
http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships
- [Answered ]-Django slug, `\w` doesn't detect korean + chinese
- [Answered ]-How can I get past this "'django_content_type' does not exist" error when deploying with Heroku?
- [Answered ]-Badly affecting performance in populating ManyToMany field values in rest api (using django rest framework)
- [Answered ]-Update data in a JsonField django
- [Answered ]-Pytz – timezone activated yet getting wrong time. Am I missing something?
- [Answered ]-Rebuild content of a Div tag in complete function of $.ajaxt
- [Answered ]-Django – Slow Ajax response seems to be delayed
Source:stackexchange.com