0

I have a model with an ArrayField:

class Item(models.Model):
    path = ArrayField(models.IntegerField(), blank=True, null=True)

The path values, for example:

{19,21, 34, 22}

I get all Item Objects which ids are in another Item path:

qs = Item.filter(id__in=item.path)

I need to get the elements, in the order that are in the path(not taking in consideration the values in the Array).

Using order_by('path') gives 'strange' results, because I suspect is taking in consideration all paths and not the order of the elements in a specific path

user3541631
  • 3,686
  • 8
  • 48
  • 115

1 Answers1

1

As by the docs, it should rather be order_by('path').

Nikita Shupeyko
  • 316
  • 2
  • 4
  • thanks, that was a typing mistake, but the suggested answer gives wrong results, because is taking in consideration all paths and not the order of the elements in the path – user3541631 Jun 16 '18 at 09:47
  • Oh, I get that now, [this thread's answer](https://stackoverflow.com/a/37648265/1557013) might be what you've been looking for. – Nikita Shupeyko Jun 16 '18 at 09:55