Also, maybe you aren't submitting all the code, but you could do the same thing by just passing an attrs dictionary to the text area widget. http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs Not sure that this requires two more classes.
Hope that helps, Alex (Robbins) On Aug 30, 12:53 am, Mark Anderson <[email protected]> wrote: > Hello, > > I wanted a field that would render in a rich text editor and store the data > in a TextField so I created a field type of HtmlField and custom HtmlWidge. > It works but I was wondering is anyone would be willing to give me feedback > on best practices etc, This is my first attempt at subclassing and any > points on would be great. I would like modelform to set the class to rte > and adjust rows/cols without me having to specify a widget. > > Thank you, > Mark > > class HtmlWidget(Textarea): > def __init__(self, attrs=None): > super(HtmlWidget, self).__init__(attrs) > > def render(self, name, value, attrs=None): > if value is None: value = '' > value = smart_unicode(value) > > return mark_safe(\ > u'<textarea name="%s" rows="12" cols="86" class="rte">%s</textarea>' > % \ > (name, escape(value))) > > class HtmlField(models.TextField): > > def get_internal_type(self): > return "HtmlField" > > def formfield(self, **kwargs): > kwargs['widget'] = HtmlWidget > return super(HtmlField, self).formfield(**kwargs) > > def __init__(self, *args, **kwargs): > super(HtmlField, self).__init__(*args, **kwargs) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

