On Dec 17, 12:03 pm, Streamweaver <[email protected]> wrote:
> Is it possible to display calculated values for models in the admin
> interface.  I know about the list_display attribute for model.Admin
> but all I really want to do is add text to a model edit form so I can
> see calculated values.
>
> For instance I have a model called Profile with a DateField called
> birthday.  I have a method as a @property that returns calculated age
> as of today.  I'd like to display the calculated age as text in the
> model editing form in the admin interface.
>
> How would I do this.
>
> i.e. displaying the property below as text in the admin interface
>
> class Profile(models.Model):
> ...
>
>     @property
>     def age(self):
>         """Returns age in years as of today."""
>         today = date.today()
>         return self.age_bydate(today)
>
> Thanks for any input.

You can add in fields to a custom form, which can do this.

class ProfileAdmin(admin.ModelAdmin):
    form = forms.ProfileAdminForm


Matt

--

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