tags:

views:

19

answers:

1

The ChoiceField creates a select html element and the options show the choice_label which is the _unicode_ of each model object.

How can I change the text of the choice_label without modifying _unicode_ ?

I have a Product model and I want to show in the options text the product name + price + link to edit.

I've searched in fields.py and widgets.py but couldn't find what needed to be changed.

Thanks

A: 

The from field class, eg. ModelChoiceField has a method label_from_instance that you can override in your subclass. Originally it looks like this:

def label_from_instance(self, obj):
    return smart_unicode(obj)  

Should be no big problem to adjust this to your needs!

lazerscience
It looks exactly like what I need. trying, thanks.
pablo