Saturday, December 11, 2010

Rendering a field value in a custom way

Hi guys,
I want to be able to render a custom field.

It's supposed to extend a normal char field. I want to place certain
content in front of the field, depending upon the fields value.

As an example take a simple field that allows entering a number.
Instead of displaying the number, I would like to display star symbols
(e.g. entering 5 would return 5 star symbols when rendered in
templates).

Can I do that by extending the field? I do not want to setup any
template extensions, I want the field to act like that naturally.

I tried overwriting the field like this:

<code>
class inPlaceCharField(models.CharField):
def __init__(self, *args, **kwargs):
self.widget = ReCaptcha
self.required = True
super(models.CharField, self).__init__(*args, **kwargs)
def render(self):
return ";;;"
def __unicode__(self):
return "123"
def __str__(self):
return "1234"
def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
return "12345"
</code>

But none of them worked - I always get the field's value rendered.
Which function do I need to overwrite?

Kind Regards and thanks for your answer in advance
Stephan

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate