#24592: order_by HStore Key/Value Pair
------------------------------+--------------------------------------------
     Reporter:  DavidMuller   |      Owner:
         Type:                |     Status:  new
  Uncategorized               |
    Component:                |    Version:  1.8
  contrib.postgres            |
     Severity:  Normal        |   Keywords:  hstore postgres order_by value
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+--------------------------------------------
 I am currently trying out Django 1.8's HStore implementation, but am
 having trouble using the ORM's order_by function.

 Say I have HStore dictionaries stored in my database like

 {{{
 {'key': 'value', 'en-US': 'english'}
 }}}

 and would like to order a queryset by the strings pointed to by one
 particular key.

 I run into 2 distinct errors trying to 'order_by' either key ('key' or
 'en-US'):

 1.
 {{{
 MyModel.objects.order_by('name__key')

 /usr/local/etc/virtualenvs/gears/local/lib/python2.7/site-
 packages/django/db/models/sql/query.py in names_to_path(self, names, opts,
 allow_many, fail_on_missing)
    1427                     raise FieldError(
    1428                         "Cannot resolve keyword %r into field.
 Join on '%s'"
 -> 1429                         " not permitted." % (names[pos + 1],
 name))
    1430                 break
    1431         return path, final_field, targets, names[pos + 1:]

 FieldError: Cannot resolve keyword 'key' into field. Join on 'name' not
 permitted.
 }}}


 2.
 {{{
 MyModel.objects.order_by('name__en-US')

 /usr/local/etc/virtualenvs/gears/local/lib/python2.7/site-
 packages/django/db/models/sql/query.py in add_ordering(self, *ordering)
    1717                 errors.append(item)
    1718         if errors:
 -> 1719             raise FieldError('Invalid order_by arguments: %s' %
 errors)
    1720         if ordering:
    1721             self.order_by.extend(ordering)

 FieldError: Invalid order_by arguments: ['name__en-US']
 }}}

 Is ordering by a particular key/value pair not something the ORM supports
 (or plans on supporting)?

--
Ticket URL: <https://code.djangoproject.com/ticket/24592>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.08012c1c2db1653a2007bb5bda153062%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to