Hi Daniel,
choices is how it is currently implemented, but it has 2 flaws:
1) this happens for all records, just when they are loaded;
2) the "translator" function, checks if the int can be used as a key
to retrieve the meaning, else (KeyError) it returns 'currently
unused'.
3) the choice solution forces me to list all the possible values
(usually less than 20 out of 255 are meaningful).

Now I am trying the ModelAdmin.render_change_form

On Tue, Jul 13, 2010 at 10:34, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 13, 9:28 am, Massimiliano della Rovere
> <massimiliano.dellarov...@gmail.com> wrote:
>> I need to "decode" the value of the fields of ModelAdmin.form so that,
>> for some fields, the int value is translated in a string showing its
>> meaning.
>> I do not want to implement this in the Model class (using
>> Model.to_python or Model.formfield for example), because the
>> information displayed in the columns of changelist_view page are
>> enough for the 90% of the times, so I prefer to do the extra work
>> necessary to generate the strings only when requested thus avoiding
>> the overhead necessary to select the correct string to be wasted in
>> most cases.
>>
>> So I was in doubt whether to override the ModelAdmin,get_form or some
>> _get_val_from_obj for some fields from the ModelAdmin.form.
>>
>> Which one is more correct in your opinion?
>
> Couldn't you just use `choices` for that? Specify the possible values
> and their 'decoded' versions in a 2-tuple, set the field's choices
> parameter to that constant, and you would automatically get a
> `get_FOO_display()` method which would show the 'decoded' value
> instead of the original one.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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