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?
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.
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.
str function in a django model returns a string that is exactly rendered as the display name of instances for that model.
@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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With