I have used django but I'm a newbie with mongodb. I have the follow model:
class Conversation(models.Model):
date = models.DateTimeField(auto_now_add=True, db_index=True)
users = ListField(models.CharField(max_length="64"), editable=False)
messages = ListField(EmbeddedModelField('Message'), editable=False)
class Message(models.Model):
user = models.CharField(max_length="64")
text = models.CharField(max_length="512");
date = models.DateTimeField(auto_now_add=True, db_index=True)
I already store and show conversations with messages for each user, but now I want to filter conversations by some users like a private chat.
For example, I want to get conversations which users contains ['Dennis','linus','Guido']
How can I do it?
Thanks in advance.
* EDIT *
I got it using Q
django.db.models.Q
Conversation.objects.filter(Q(users = msg['Dennis'])&Q(users = msg['linus']&Q(users = msg['Guido']))
Is there a better approach?