A
A
Adilet Usonov2020-12-12 15:53:04
Django
Adilet Usonov, 2020-12-12 15:53:04

How to shorten text in Django admin?

Maybe a stupid question, but is it possible to somehow limit the text of a row in a table (in the django admin) so that all rows are the same size?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Eremin, 2020-12-12
@Adilet-novichok

In the model, you add a string truncation function, for example:

def trim50(self):
        return u"%s..." % (self.szYouFileldNeedTrim[:50],)

In the admin, instead of specifying the field szYouFileldNeedTrimthat you want to shorten when outputting, you specify this function trim50. When editing a record, real fields will be loaded (i.e. in our case, szYouFileldNeedTrim ), and in the record label, a synonym for trim50

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question