2014年12月27日 星期六

[Django] Human readable text in admin panel

In Django, when we are dealing with the admin panel, we can specify human readable text for the column through different methods


  1. Make it when building the corresponding model
    e.g.1: question_text = models.CharField('question', max_length=200)
    e.g.2: pub_date = models.DateTimeField('date published')

  2. Django makes the first parameter as the field show in admin UI, in this case "Date published" and "Question" will be shown.

  3. Or, you can make it through the admin.py, Django's build-in admin model

    short_description 
  4. e.g.: was_published_recently.short_description = 'Published recently?'

    The corresponding column will be shown with readable text

  5. Or you let Django do the rest of the job using class option 'list_display'

    list_display = ('first_name', 'last_name')

    Django will set column name as First name and  Last name where they are both 'database fields', underscores will be evaluated as spaces

沒有留言:

張貼留言