https://docs.djangoproject.com/en/4.0/topics/db/aggregation/#following-relationships-backwards
says to note that book is the auto-generated reverse relation instead of book_set in annotations but doesn’t explain why. Is it an arbitrary design decision or is there a deeper reason? Where else is the _set ommited?
I know related_name can remove the _set. I’m talking about the autogenerated names.
Thank you
I don’t have a definitive answer - or even direct knowledge of the situation - but my impression is that if you’re specifying something being sent to the server as part of a query, then you don’t need that suffix. As another example, if you’re creating a filter that follows a relationship backwards, the _set
suffix isn’t required there, either. (See Making queries | Django documentation | Django)
However, if you’re specifying something that operates in Django as a manager, then you would need to use _set
.
(That seems to explain the behavior for the situations that I can think of - I’d be curious to see if there is a counter-example to that general principle.)