Therefore, you would have to go about this in some other way. One
option which I have used is to add a new column to your Model, and pre-
populate it with a zero-padded string representation of your number
column in your Model's overriden save() method. It's extra data, but
the only easy way to implement this.
In an SQL query, this would be pretty simple to implement, using
to_char() (for postgres) or lpad(cast()) for MySQL, to create an
"alias" column. If there is a way to do this in Django, I'd like to
know about it, because it would be pretty darn useful - although
totally DB specific. I'm thinking a read-only column based upon a SQL
fragment, which could then be mapped to a Django model attribute, and
referenced in an order_by() clause.
In your model add method like this:
def _get_foo(self):
return self.the_display_column
_get_foo.short_description = "Whatever"
_get_foo.admin_order_field = "the_sort_column"
Django looks for those special method attributes. More info here
http://www.djangoproject.com/documentation/admin/
And in your ModelAdmin just include "_get_foo" in the list_display.
class MyModelAdmin(admin.ModelAdmin):
list_display = ("_get_foo", "some_other_column, )
--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun! Check out Austin360.com for all the entertainment
info you need to live it up in the big city!
Hey, I'm thrilled there's an easier way. I don't like extra work
either. I'll have to look into this some more.
Ah! I missed that admin_order_field bit. That was the only reason I
haven't been using functions that way - they wouldn't sort.
Thanks Norman!