I am developing a web application with django, backbone.js, tastypie and mongodb. To adapt tastypie and django to mongodb, I use django-mongodb-engine and tastypie-nerel. This application has a model project in which there is a list of tasks. So it looks like this:
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)
Thanks to the tastypie-nerelle, getting a list of project tasks is done in a simple way by using a GET request in / api / v 1 / project /: id: / tasks /
Now I want to expand this task model with a list of comments:
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)
The problem with this implementation is that tastypie-nonrel does not support another attachment, so it is not possible for a simple POST to comment on / api / v 1 / project /: id: / task /: id: / comments /
An alternative is to simply make a PUT request for task / api / v 1 / project /: id: / task /, but this will create problems if two users decide to add a comment to the same Task at the same time, since the last PUT will cancel previous.
The last option (in addition to changing tastypie-nonrel) is to not insert the Comment inside the Tasks and just keep the ForeignKey, so the request will go to / api / v 1 / Comment /. My question is, does this violate the benefits of using MongoDB (cross-query as needed)? Is there a better way to do this?
I have little experience with any of the stack technologies, so maybe I am not focusing on the problem. Any suggestions are welcome.