Hi,

I've been trying to build a custom calculated column and it always shows as (empty) in the admin interface list view.

The column is shown, and the callable seems to be called, but does never show any value except empty. no matter what it returns. Also, the column header is set to the specified value ... so why is the value missing?

Can someone please tell me what i'm doing wrong? I tried it with all variants described there: https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

Registering is done, also the model class is fine, only the damn calculated field has no value!

Admin.py:


class MemberAdmin(admin.ModelAdmin):
fields = (
    'member_id',
    ('first_name', 'last_name', 'birth_date'),
    )

list_display = ('first_name', 'last_name', 'birth_date', 'age')

def age(self, obj): """ return the current age in years """ today = datetime.date.today() delta = self.birthdate - today #return str(int(delta.days / 365.25)) return "12"

age.short_description = 'Age Col' age.admin_order_field = 'birth_date'

asked 08 Sep '13, 10:45

BGinner's gravatar image

BGinner
113
accept rate: 0%

edited 08 Sep '13, 10:49


class MemberAdmin(admin.ModelAdmin):
   fields = (
        'member_id',
        ('first_name', 'last_name', 'birth_date'),
        )

   |list_display = ('first_name', 'last_name', 'birth_date', 'age')

   |def age(self, obj):
   |    """ return the current age in years """
   |    today = datetime.date.today()
   |    delta = self.birthdate - today
   |    #return str(int(delta.days / 365.25))
   |    return "12"
   |
   |
   |age.short_description = 'Age Col'
   |age.admin_order_field = 'birth_date'

as above, should be
I think there is a problem in the recesses

link

answered 20 Sep '13, 10:15

mcihad's gravatar image

mcihad
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×3
×1
×1
×1

Asked: 08 Sep '13, 10:45

Seen: 1,079 times

Last updated: 20 Sep '13, 10:15

powered by OSQA