Where to use _set and when to simply use the field name

In the video at 19:00 sir used models.author.article_set.all to access all the article written by the author so going by the trend while accessing authors of an article we should have used models.article.author_set.all but that didn’t happen can u explain where to use _set and when to simply use the field name.

Hello @Kunal_ar0ra, this _set is used in case of many to one relationship or many to many relationship cases. And here the relation is many to one. Many articles can be related to a single author. And here we need to access that for a particular author what is the set of the articles he has written or the article set that is associated to him.
So here article_set is signifying the set of the articles.
Now, suppose I have an author let’s denote it from a1 and now we need to check all his articles we can query like,
a1.article_set.all() to know all the articles written by him.
So, this will return the queryset of the articles. If we need to count how many articles are written by the author we can query like
a1.article_set.count()
Similarly we can add or query anything else on this just like a normal queryset.
For more such examples and details I suggest you to visit here https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
In case you feel any confusion pls ask I will surely try to help you out.

there is many to many relationship between article and authors.So while accessing articles related to a specific author I am using article_set , but while accessing all the authors related to an article we don’t use author_set .Why?

Hey !! sorry I didn’t see that video and for misunderstanding the structure of the tables. @Kunal_ar0ra here we defined authors inside the class of articles so we can access that the authors by using like for article having name a1 we can do a1.authors.all() and suppose any author with name auth1 we can see its articles by using auth1.articles_set.all()
It is totally depends upon how your tables are organised and where you are defining the relation. Here we defined the relation inside the articles class.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.