Hi,
I a have a question about changing help_text in a model derived from 
another model. In my case, all of the models use the same form, generated 
from model.

Few classes share the same TextField. But the meaning of the field is 
different in different models. The following is a simplified version to 
illustrate the question, errors are probably added ;-).

#models.py:
from django.utils.html import format_html
import django.db.models.options as options

options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('help_texts',)

class Fact(models.Model):
"Model with plain text"
name = models.TextField(help_text="Simple text, it will be escaped in html")

def __unicode__(self):
return self.name

class ReST(Fact):
"""Derived model with ReStructured Text, it will be converted to html and 
marked safe.
This model needs a different self.name.help_text, but assigning to it in 
__init__ is not possible (self.name is None when __init__ is running)
"""
def __unicode__(self):
return format_html(rest_to_html(self.name))

class Meta:
help_texts = {'name': 'You can use ReST formating here.'}

#views.py:
class BaseCreateView(CreateView):
def get_form_class(self):
model = class_by_name(self.kwargs['fmname'])
opts = model._meta
if hasattr(opts, 'help_texts'):
for fl in opts.concrete_fields:
if fl.name in opts.help_txt:
fl.help_text = opts.help_txt[fl.name]
form = model_forms.modelform_factory(model)
return form


The above use of Meta results in a situation, that with one class more 
(derived from ReST), its help_text value depends on history of using forms 
for ReST and Fact...

My question: is there a way to change help_text of a model field defined in 
a parent class from within a derived model class?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e5607dc-d44c-4fe9-a450-fa3b738b3600%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to