django-ajax
django-ajax copied to clipboard
Encoding select_related
Is there a way to get encode_data to recognize models pulled in with select_related in the queryset passed to it?
I hadn't even heard of select_related
before you mentioned this, so I have no idea. What I do know is the expand
option on encode_record
will do what you're looking for for ForeignKey
fields. This is one of the issues with the project: encode_data
and encode_record
behave somewhat differently.
I think what you'll want to do is loop over your QuerySet
and use encode_record
on each model instance rather than encode_data
on the entire QuerySet
. I think the DefaultEncoder
, which should supersede the old encode_data
/encode_record
does this now.
I tried looping over them but it still doesn't pull in my model, which has a OneToOne relationship with the main one. Does it work with OneToOne models?
Probably not. If you checked for both ForeignKey
and OneToOne
in this line of code, it might work:
https://github.com/joestump/django-ajax/blob/master/ajax/endpoints.py#L39