Hello,

I have searched high and low and have not been able to find a way to
get the form errors to display the label/verbose_name.  As of now the
{{ GeneralForm.errors }} prints a <ul> of the field name and errors
listed for the field.  This output is fine but I would like the label/
verbose_name to be displayed and not the name of the DB field.

Here is my current model:
class Generic(models.Model):
        CaseNumber = models.CharField(verbose_name='Case Number',
maxlength=50)
        User = models.ForeignKey(User, editable=False)
        Fname = models.CharField(verbose_name='First Name', maxlength=100,
null=True, blank=True)
        Lname = models.CharField(verbose_name='Last Name', maxlength=100,
null=True, blank=True)
        Mname = models.CharField(verbose_name='Middle Name', maxlength=100,
null=True, blank=True)

View:
def generic_form(Request, CaseID = 0):
        data_content = {}
        data_content['CaseID'] = CaseID

        if CaseID == 0:
                oGenericForm = form_for_model(Generic,
formfield_callback=generic_callback)
        else:
                oGeneric = Generic.objects.get(id=CaseID)
                oGenericForm = form_for_instance(oGeneric,
formfield_callback=generic_callback)

        if Request.method == 'POST':
                if Request.POST.has_key('frmSaveGeneral'):
                        oForm = oGenericForm(Request.POST)
                        if oForm.is_valid():
                                oGeneric = oForm.save(commit=False)
                                if CaseID == 0:
                                        oGeneric.User_id = Request.user.id
                                        
Request.user.message_set.create(message="The new case was
sucessfully saved.")
                                        oGeneric.save()
                                        return 
HttpResponseRedirect('/system/case/%i/' % oGeneric.id)
                                else:
                                        
Request.user.message_set.create(message="The case details were
sucessfully saved.")
                                        oGeneric.save()
                else:
                        oForm = oGenericForm()
        else:
                oForm = oGenericForm()

        data_content['GeneralForm'] = oForm

        return render_to_response('system/case/general.htm', data_content,
context_instance=RequestContext(Request))

Template (small section):
{% if messages %}
        {% for message in messages %}
                <div id="message_good">{{ message }}</div>
        {% endfor %}
{% else %}
        {% if GeneralForm.errors %}
                <div id="message_bad">
                        The following error occurred:
                                {{ GeneralForm.errors }}
                </div>
        {% endif %}
{% endif %}

Any ideas would be most appreciated.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to