Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access django model fields label and help_text

Tags:

django

I have something like this:

class ContactData(models.Model):     name  = models.CharField(max_length=300, verbose_name=u"Name", help_text=u"Please enter your name...",null=True, blank=False)     phone = models.CharField(max_length=300, verbose_name=u"Phone number", null=True, blank=False) 

I would like to show a field's label and help_text in template (that is - just access it from view). Can this be done?

like image 942
frnhr Avatar asked Nov 25 '10 18:11

frnhr


People also ask

How do I get form fields in Django?

Basically to extract data from a form field of a form, all you have to do is use the form. is_valid() function along with the form. cleaned_data. get() function, passing in the name of the form field into this function as a parameter.

Is there a list field for Django models?

Mine is simpler to implement, and you can pass a list, dict, or anything that can be converted into json. In Django 1.10 and above, there's a new ArrayField field you can use.

What is __ Str__ in Django?

str function in a django model returns a string that is exactly rendered as the display name of instances for that model.

What is Auto_created in Django?

@Raphael In a migration, an auto_created model gets created by the AddField operation for the ManyToManyField -- it does not exist as a separate model, only as part of the model that defines the m2m field.


1 Answers

unicode(ContactData._meta.get_field('name').verbose_name) unicode(ContactData._meta.get_field('name').help_text)  unicode(ContactData._meta.get_field('phone').verbose_name) unicode(ContactData._meta.get_field('phone').help_text) 
like image 160
user1649195 Avatar answered Sep 26 '22 11:09

user1649195