If you’re sure there are only integers in the field, you could get the database to cast it as an integer via the extra
method, and order by that:
MyModel.objects.extra(
select={'myinteger': 'CAST(mycharfield AS INTEGER)'}
).order_by('myinteger')
More Related Contents:
- Django admin: how to sort by one of the custom list_display fields that has no database field
- Extending the User model with custom fields in Django
- How can I get the full/absolute URL (with domain) in Django?
- Django stops working with RuntimeError: populate() isn’t reentrant
- How to resolve “django.core.exceptions.ImproperlyConfigured: Application labels aren’t unique, duplicates: foo” in Django 1.7?
- Creating a extended user profile
- Django 1.11 Annotating a Subquery Aggregate
- How to update an object from edit form in Django?
- selenium.common.exceptions.InvalidCookieDomainException: Message: invalid cookie domain while executing tests in Django with Selenium
- Track the number of “page views” or “hits” of an object?
- Django Static Files Development
- Django Broken pipe in Debug mode
- Tying in to Django Admin’s Model History
- django class-based views with inline model-form or formset
- How to automate createsuperuser on django?
- Overriding AppConfig.ready()
- How can I call a custom Django manage.py command directly from a test driver?
- Add class to form field Django ModelForm
- “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” in django
- django dynamically filtering with q objects
- how to show datepicker calendar on datefield
- Order by count of a ForeignKey field?
- Django {% static ‘path’ %} in javascript file
- Byte Ranges in Django [closed]
- Django ORM: Group by and Max
- Nginx connection reset, response from uWsgi lost
- Django queryset get exact manytomany lookup [duplicate]
- Django / Comet (Push): Least of all evils?
- 110: Connection timed out (Nginx/Gunicorn)
- How to show related items using DeleteView in Django?