I just found a way to do this without having to create a class for the relationship. It relies on the extra
feature that lets you add additional columns to output. In your example it would look like:
theuser.following.filter(user__is_active=True)
.extra(select={'creation_seq': 'appname_user_user_following.id'})
.order_by("creation_seq")
Notice that appname_user_user_following
is the name of the relationship table Django creates under the covers. It's deterministic and something you can get and set via meta-mechanisms, but it's pretty much safe to hardcode.
Here's an example of the SQL that's being created under the covers with fake table and columns names:
SELECT (appname_user_user_following.id) AS `creation_seq`, `appname_user`.`id`
FROM `appname_user` INNER JOIN `appname_user_user_following` ON
(`appname_user`.`id` = `appname_user_user_following`.`user_id`) WHERE
`appname_user_user_following`.`user_followed_id` = 1 ORDER BY `creation_seq` ASC';
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…