0

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?

1 Answer 1

1

I suppose you're using mongoengine?

Conversation.objects.filter(users__all=['Dennis','linus','Guido'])
Sign up to request clarification or add additional context in comments.

10 Comments

is __all a valid queryset filter option ? You probably mean __contains
Ok.. but does the django orm support that was my question.
Exactly.. thats what i m trying to say.
:) if so, use mongoengine to retrieve conversations and the django orm (with mysql or anything) for everything else.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.