Re: Format fields in list, but keep sortable?
Chris: Sure, there's that possibility – however, I think it would be very bad practise to insert a redundant field like this, just for formatting matters. Also, one might want the option of using localised units, etc. Shawn: Of course you are generally correct and I know that the core developers keep reminding everyone of this fact. However, they themselves have implemented a lot of "niceness" in the admin lists (boolean icons, date formatting etc), so I think this trivial formatting matter is not about going beyond the scope of the admin. Also, rewriting the whole admin application just because you want to format some fields in a different way would be a bit exaggerated. Also, I don't think you have to call yourself lazy for making the most of what's already there. I suppose there is not a really easy way, then. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Format fields in list, but keep sortable?
Bear in mind that the admin has a limited scope. This is intentional. It was meant to be a friendly replacement for having to hit the Postgres/mySQL command line interface, and that's about it. It's trivial to create your own form for dealing with your model which can be customized in any way you like. This is not intended to be a snarky response. Partially it's a PSA, and partially a reminder to myself; the admin is so great that it makes me lazy, and I end up living without some really convenient functionality because the admin "almost does it." Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Format fields in list, but keep sortable?
You could add a field to store the calculated size, and override the model's save method to perform the necessary calculation. Something like: def save(self, force_insert=False, force_update=False): self.size_formatted = self.width * self.height // or whatever your calculation actually is super(ModelName, self).save(force_insert, force_update) Be sure to replace 'ModelName' with the name of your model. On Dec 8, 7:18 am, philomatwrote: > Hi, > > I keep numeric fields like "size", "width", "height" in my database. > In the admin, I want to render them in a friendly format and attach > units like "KiB" or "pixels" to them when showing them in the change > list. I know this could easily be achieved by adding callables such as > "size_formatted" etc to list_display. However, these are no longer > sortable. > > Is there a way around this limitation? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.