Skip to content

Instantly share code, notes, and snippets.

@jorgebastida
Created August 22, 2012 11:16
Show Gist options
  • Select an option

  • Save jorgebastida/3424560 to your computer and use it in GitHub Desktop.

Select an option

Save jorgebastida/3424560 to your computer and use it in GitHub Desktop.

Revisions

  1. jorgebastida created this gist Aug 22, 2012.
    16 changes: 16 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    class Comment(db.EmbeddedDocument):
    ...
    visibility = db.IntField(default=0)
    mentions = db.ListField(db.GenericReferenceField())


    class Message(db.Document):
    ...
    comments = db.ListField(db.EmbeddedDocumentField(Comment))



    # I want the list of Messages that have comments that ment a particular user and they are visible (the comments):

    user = User.objects.get( ... )
    Message.objects(__raw__={'comments': {'$elemMatch': {'visibility': 0,'mentions': {'_cls': 'User', '_ref': user.to_dbref()}}}})