django-tastypie-nonrel icon indicating copy to clipboard operation
django-tastypie-nonrel copied to clipboard

List of ForeignKey (List of reference to other objects)

Open kfrancoi opened this issue 13 years ago • 6 comments

Hello

I just posted a question on Stackoverflow related to the possibility for a Resource to resolve a list of ForeignKey (Object ID) to other objects and make it accessible in the API.

http://stackoverflow.com/questions/9434823/django-mongodb-tastypie-nonrel-list-of-foreignkey

I think this would be a very useful feature for tastypie-nonrel. Do you agree ?

Thank you

kfrancoi avatar Feb 24 '12 17:02 kfrancoi

I don't understand why there is not way to have field that encapsulate list of ForeignKey. If I'm not misunderstanding, I think it is a common pattern in NoSQL ? EmbeddedModel place an object A inside another objectB, but any modification on the object A independently of the object B will not be reflect in the object B.A. With a list of ForeignKey in the object B containing references to objects A will ensure that consistency.

Are you OK with that ? I want to be sure I'm understanding NoSQL correctly :-)

http://stackoverflow.com/questions/9434823/django-mongodb-tastypie-nonrel-list-of-foreignkey

Thanks

kfrancoi avatar Feb 29 '12 10:02 kfrancoi

Sure, it's an idiomatic pattern -- IIRC it works in Django. (I don't know about tastypie though)

jonashaag avatar Feb 29 '12 23:02 jonashaag

Thanks,

However, I can't find a reference to a Django documentation where it's shown how to handle a list of ForeignKey ?

Basically, what I'm trying to develop is a new field for django-tastypie-nonrel that act as a EmbeddedListField but access sub-object by reference (using ForeignKey) instead of embedding them.

Any comment on that is welcome.

kfrancoi avatar Mar 01 '12 09:03 kfrancoi

Hi,

I solved my problem by writing a new tastypie-nonrel field to handle list of ForeignKey. If contributors of this project are interested, I'm happy to discuss on how we could integrate this in a future version.

Thanks

kfrancoi avatar Mar 05 '12 21:03 kfrancoi

@kfrancoi sorry for the slow reply. I haven't looked at that specific problem in a while, but I remember there was something problematic about it. Do you have a patch for it? We also need to merge tastypie-nonrel with a more current version of tastypie, since there have been some major changes in the parent project.

andresdouglas avatar Apr 09 '12 23:04 andresdouglas

@andresdouglas thanks for your answer. I think I solved the need to have a list of foreignKey to other models, based on your work. It has been tested for both GET and POST requests. I think Tastypie is a very good product, and there is a clear need to extend that it's functionality to nonrel databases. So please, don't hesitate to put me in the loop if you want to improve your project (-> tastypie-nonrel).

kfrancoi avatar Apr 12 '12 08:04 kfrancoi