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
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 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
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"
4 matches
Mail list logo