Working on some code I've hit that the reverse name for a OneToOneField cannot be used, it seems, in values_list or values. I couldn't see why there would need to be such an exclusion, given it is a one-to-one relationship, so am wondering if it's just an oversight in the code or a deliberate exclusion?
The portion of code that is rejecting doing e.g. "values_list('onetoonereversename')" is in setup_joins where the if line reads: if not allow_many and (m2m or not direct): The values of "m2m" and "direct" come from opts.get_field_by_name and it seems that the reverse of a OneToOne gives the same results as the reverse of a ForeignKey, as of course both are not m2m and are not direct. Looking at the code later on in setup_joins it describes the path where direct is false and m2m is false as being "One-to-many field (ForeignKey defined on the target model)", so it looks like the logic I've quoted above of "if not allow_many and (m2m or not direct)" has the "not direct" clause in to reject reverse ForeignKey relationships and in doing so also rejects reverse OneToOne relationships (and with the latter case I suspect it need not!). If someone a bit more knowledgeable about the query machinery could comment on whether it does look like an oversight or is a deliberate exclusion, then if it's the former I'll log it as a bug. Assuming the rest of the code is ok in the case of a reverse OneToOne then something along the lines of "if not allow_many and (m2m or (not direct and not isinstance(getattr(field,'field',None),OneToOneField))" instead could work to allow OneToOne reverses through in setup_joins when allow_many is False. Regards, Matt -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.