2

Given the models:

class Post(models.Model):
    datas = ListField(EmbeddedModelField('Comment'),blank=True)
    data = DictField()

class Comment(models.Model):
    name = models.CharField(max_length=255)
    date = DateField(blank=True, null=True)

If we set the data variable to:

{'key':'value'}

Is there a way to filter for Posts with key=='value'?

As an alternative, what about with embedded documents? Is there a way to filter for a Post that has an author with the name 'Ralph'?

It seems like this must be possible, or else this ORM is far too limiting to be useful, which seems unlikely.

neuman
  • 125
  • 1
  • 8

2 Answers2

0

I recommend trying it out for yourself, but the comment in the code

#TODO/XXX: Remove as_lookup_value() once we have a cleaner solution # for dot-notation queries

suggests that it does. I've ever only really used lists.

emperorcezar
  • 334
  • 1
  • 9
0

You can filter for a Post that has an author named "Ralph" using raw queries:

Post.objects.raw_query({'author.name': "Ralph"})
Jonas H.
  • 2,331
  • 4
  • 17
  • 23