Note that there are some explanatory texts on larger screens.

plurals
  1. POTastypie-nonrel, django, mongodb: too many nestings
    primarykey
    data
    text
    <p>I am developing a web application with django, backbone.js, tastypie and mongodb. In order to adapt tastypie and django to mongodb I am using django-mongodb-engine and tastypie-nonrel. This application has a model Project, which has a list of Tasks. So it looks like this:</p> <pre><code> class Project(models.Model): user = models.ForeignKey(User) tasks = ListField(EmbeddedModelField('Task'), null=True, blank=True) class Task(models.Model): title = models.CharField(max_length=200) </code></pre> <p>Thanks to tastypie-nonrel, getting the list of task of a project is done in a simple way with a GET request at /api/v1/project/:id:/tasks/ </p> <p>Now I want to extend this Task model with a list of comments:</p> <pre><code> class Task(models.Model): title = models.CharField(max_length=200) comments = ListField(EmbeddedModelField('Comment'), null=True, blank=True) class Comment(models.Model): text = models.CharField(max_length=1000) owner = models.ForeignKey(User) </code></pre> <p>The problem with this implementation is that tastypie-nonrel does not support another nesting, so is not possible to simple POST a comment to /api/v1/project/:id:/task/:id:/comments/ </p> <p>The alternative is to just make a PUT request of a Task to /api/v1/project/:id:/task/, but this would create problems if two users decide to add a comment to the same Task at the same time, as the last PUT would override the previous one.</p> <p>The last option (aside from changing tastypie-nonrel) is to not embed Comment inside the Task and just hold the ForeignKey, so the request would go to /api/v1/Comment/. My question is if this breaks the benefits of using MongoDB (as it is needed cross queries)? Is there any better way of doing it? </p> <p>I have little experience in any of the technologies of the stack, so it may be I am not focusing well the problem. Any suggestions are welcome.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload