i have a query regarding "related_name" parameter (used while establishing a relationship between models)
suppose i assign the value to related_name= "x"
then,
it sets the given value to reverse relation manager name ex- parent_model_object.x.all()
it sets given name to parent model while filtering objects. ex - child_model.objects.filter(x__name = "manav")
so is there any chances of name conflict ? (as same name is assigned to model_class and reverse relation manager )
so is there any chances of name conflict?
No: Django checks this. It will try to add the name in reverse, and it will print an error in case there is.
The .filter(…)
[Django-doc] by the way does not work with the related_name=…
[Django-doc], but with the related_query_name=…
[Django-doc]. If no related_query_name=…
is set, it will default to the related_name=…
, and if that is missing too, to the model name in lowercase. This is different from related_name=…
itself, which defaults to the modelname_set
with modelname
the name of the model in lowercase.