Django-nonrel listfield lookup on mongedb

560 views Asked by At

From the below example on mongodb, what would be preferred way for lookup:

from djangotoolbox.fields import ListField, EmbeddedModelField

class Post(models.Model):
    ...
    comments = ListField(models.ForeignKey(Comment, related_name="post", null=True, blank=True), null=True, blank=True)

class Comment(models.Model):
    text = models.TextField()
    created_on = models.DateTimeField()


post_id = 4eaa636b600998598c000018  

Neither one of following works:

posts = post.objects.filter(comments =('text', 'test'))
posts = post.objects.filter(comments =('pk', post_id))
posts = post.objects.filter(comments =('in', post_id))
1

There are 1 answers

0
emperorcezar On

Right now there is little support for a ForeignKey in a ListField.

But, I'm working on changing this right now: https://bitbucket.org/emperorcezar/djangotoolbox

So far I have inserting objects working. post = Post(comments = [comment_obj]) and am working on lookups right now.

Hopefully this will be supported soon if I can get it working and my pull request is accepted.