django-ajax icon indicating copy to clipboard operation
django-ajax copied to clipboard

Encoding select_related

Open lsemel opened this issue 13 years ago • 3 comments

Is there a way to get encode_data to recognize models pulled in with select_related in the queryset passed to it?

lsemel avatar Jul 05 '11 21:07 lsemel

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.

joestump avatar Jul 05 '11 21:07 joestump

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?

lsemel avatar Jul 05 '11 21:07 lsemel

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

joestump avatar Jul 05 '11 21:07 joestump