I had at one time included the following and ended up putting it back
so that syncdb would actually create the columns. Without it the
table is created with the column being made. I am assuming this is
correct but am not sure.
def db_type(self):
return TextField().db_type()
Thanks for pointing out passing attrs because I did that originally.
This is more because i am auto generating forms for all loaded models
using a generic add object application I wrote. I chose this route
because I didn't want to have to manually create forms for each.
Thanks again for your input.
Mark
On Aug 30, 8:03 am, Alex Robbins <[email protected]>
wrote:
> 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....
> 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
-~----------~----~----~----~------~----~------~--~---