Hi,

Reading http://docs.djangoproject.com/en/dev/ref/contrib/admin/, I am
a bit confused on how to display the age of a person in the admin-
console.

<snip>
class UserProfile(models.Model):
  """ """
  user = models.ForeignKey(User, unique=True)

  addresses = models.ManyToManyField(Address, through='PersonAddress')
  prefered_language = models.CharField(max_length=2,
choices=LANGUAGES, default=u'en', help_text=_('Preferred language used
by the User'))
  # TODO : Add a many-to-many link through an intermediate mapping
one-2-many <--> many-2-one
  #        for the language skills (spoken / written / read + possible
official certifications).

  # TODO : Add a constraints that COUNTRY + National number are unique
  nationality = models.ForeignKey(Country)
  national_nbr = models.CharField(max_length=100, unique=True, \
                                  help_text=_('National register
number / Social Security number / ...'))
  gender = models.CharField(max_length=1, choices=GENDER_CHOICES,
default=u'U', \
                            help_text=_('Gender are officially defined
(M=Male, F=Female, U=Unknown, O=Others (rare!!!))'))

  date_birth = models.DateField(null=True, help_text=_('The date the
person was born'))
  place_birth = models.CharField(max_length=150, null=True,
help_text=_('The place the person was born in the format (City,
Country)'))
  created_on = models.DateTimeField(auto_now_add=True,
help_text=_('The day it was first inserted'))
  updated_on = models.DateTimeField(auto_now=True, help_text=_('Last
updated on'))
  accepted_on = models.DateTimeField(auto_now=True, null=True,
help_text=_('When the user was officially registered'))

  def age(self):
    return age_in_years(self.date_birth)
  def __unicode__(self):
    return self.user.first_name + ' ' + self.user.last_name + ' Acc:
\'' + self.user.username + '\' (Nationality :' +
self.nationality.iso_code + ')'

  age.allow_tags = True         # ???

  class Meta:
    verbose_name = _('Person profile')
    verbose_name_plural = _('Persons profile')
    ordering = [ 'user' ]
  ... #
</snip>


I would like to display the age in the admin-console. I added an
admin.py in the module. Here is a sniplet of the interesting par of
the code :

<snip>

class UserProfileAdminInline(admin.StackedInline):
  model = UserProfile
  fields = [ 'prefered_language', 'nationality', 'national_nbr',
'gender', 'date_birth', 'place_birth']


class UserAdmin(admin.ModelAdmin):
  """ """
  fieldsets = (
        ( _("Authentication"), {'fields': (('username', 'password'),
('first_name', 'last_name', 'email'))}),
        ( _("Permissions"), {'fields': (('is_staff', 'is_active',
'is_superuser'), 'user_permissions')}),
        ( _("Important dates"), {
            'classes': ('collapse',),
            'fields': ('last_login', 'date_joined')}),
        ( _('Advanced options'), {
            'classes': ('collapse',),
            'fields': ('groups', )
        }),
    )

  inlines = [UserProfileAdminInline]

  list_display = ( 'first_name', 'last_name', 'username', 'email',
'last_login', 'is_staff', 'is_active', 'is_superuser')
  list_display_links = ( 'first_name', 'last_name', 'username',
'email' )
  # list_filter = ('is_staff', 'is_superuser')
  ordering = ('-is_active', 'last_name', 'first_name',  'username',
'is_staff', 'is_superuser')
  search_fields = ('first_name', 'last_name', 'username', 'email')

  list_select_related = True
  save_on_top = True
  save_as = True
</snip>


How to have the age displayed... ?

Tx,

\T,


ps :

The Permissions flags are not very well aligned due to the fact that
"comments" are taking a lot of space ...

<snip>
 ...
 fieldsets = (
        ( _("Authentication"), {'fields': (('username', 'password'),
('first_name', 'last_name', 'email'))}),
        ( _("Permissions"), {'fields': (('is_staff', 'is_active',
'is_superuser'), 'user_permissions')}),         # All on one line
  ...
</snip>

How to align the comments differently  ... ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to