On Thu, Oct 18, 2012, Marc Aymerich <glicer...@gmail.com> wrote:

>On Wed, Oct 17, 2012 at 12:21 AM, Daniele Procida <dani...@vurt.org> wrote:
>> I am starting to customise the admin classes for my models so that I
>can provide extra feedback to the user.
>>
>> For example I want to report - in the admin page - useful information
>about how the system will interpret the current state of the object
>being edited.
>>
>> I'm doing this by using readonly_fields, that contain the output of
>method on the ModelAdmin class, a bit like this:
>>
>>     class PersonAdmin(ModelAdmin):
>>         readonly_fields = ['check_address',]
>>
>>         def check_address(self, instance):
>>             return instance.get_full_address or "<span
>class='errors'>Warning: I am unable to work out an address for this
>person.</span>"
>>
>> (the actual examples are rather more complex, but this is the idea).
>>
>> Does a more elegant way of doing this exist, either in Django's core
>already, or using some package that makes it easier?
>>
>
>don't know for a best way, but for me the one you're describing its
>actually a good workaround that maybe I'll use :)
>thanks for sharing !

You're welcome!

Note that you can also use methods of the Model as readonly_fields, but you 
can't use properties (because you can't assign attributes to the properties 
that you might need, like:

    check_address.short_description = "Address" # a bit like verbose_name
    check_address.allow_tags = True # so you can use HTML in the output
    
).

It would maybe be nicer to be able to use properties, for me anyway, since 
really these are attributes of the model class, and might also want to use 
elsewhere.

Daniele

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

Reply via email to