order_with_respect_to generated method names

Hi! I have a hopefully quick question regarding order_with_respect_to and the method names it generates on the “containing” model. Given the following model definition:

class PostContent(BlogObject):
parent = models.ForeignKey(
Post, related_name=‘contents’, on_delete=models.PROTECT)

the Post model now has a “set_postcontent_order()” method available; shouldn’t that be “set_contents_order()” (ie utilizing related_name)? Wouldn’t this break if Post had multiple, differently ordered PostContent fields?


I don’t think so.

The order_with_respect_to is an attribute of the Meta class of the model containing the foreign key. You can only have one such definition, and it’s defined as a reference to the field name, not the model name. (first sentence)

In other words, if Post had multiple foreign key fields to PostContent named pc1, pc2, and pc3, you would pick one of them and define it as as the order_with_respect_to. That Django names the function get_postcontent_order doesn’t really affect this. You’re only going to have one of these in your model. (I’m guessing that the use of the lowercased model name in the function name has some internal significance, but I have no idea what that might be.)

But I’m not sure I see where a conflict can arise.