joestump / django-ajax

A simple framework for creating AJAX endpoints in Django.
http://github.com/joestump/django-ajax
BSD 3-Clause "New" or "Revised" License
260 stars 54 forks source link

Encoding select_related #11

Open lsemel opened 13 years ago

lsemel commented 13 years ago

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

joestump commented 13 years ago

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.

lsemel commented 13 years ago

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?

joestump commented 13 years ago

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