At least on 2.7, python has no trouble with this:
d={'x-y': 4}
>>> import json
>>> json.dumps(d)
'{"x-y": 4}'
>>>
So that leave's Django's parsing of the order_by string, or just possibly
the database connector.
It probably won't work, but you could try:
MyTable.objects.all().order_by("'myfiel
I think the easiest way would be to convert the dash to an underscore to
follow python standards when it comes to naming. reason being, a dash is
analogous to the subtraction mathematical operation so you're requiring
python to know the difference in the usage of this character in names and
op
order_by function gets error if the field name or json key, has a dash.
I know Django use a dash for asc or desc methods. but in this case the dash
is in the middle.
EXAMPLE:
MyTable.objects.all().order_by('myfield__en-us')
I have a jsonb field like:
{
"es": "C
> Can I order_by a function within the model? I know you can list them
> in the admin inteface, etc. But can you order_by a model function? Or
> would you have to write a custom piece of code to do that?
In addition to the two solutions that John mentioned, you can do the
following in many cases:
I wanted the same thing long ago, you have a couple of choices: 1. Use
custom SQL functions (but kinda locks u in), 2. Use the python sort
function. This basically takes ur queryset, turns it into a list and
then sorts it.
Since all querysets are just lists in python you can do this:
orderedlis
Check out
http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields
2008/11/21 Luke Seelenbinder <[EMAIL PROTECTED]>:
>
> Can I order_by a function within the model? I know you can list them
> in the admin inteface, etc. But can you order_by a model function? Or
> would you have
Can I order_by a function within the model? I know you can list them
in the admin inteface, etc. But can you order_by a model function? Or
would you have to write a custom piece of code to do that?
Thanks,
Luke
--~--~-~--~~~---~--~~
You received this message becaus
7 matches
Mail list logo