[Chennaipy] iterate through the columns for an object in model

Harshit Lingamneni harshitlingamneni at gmail.com
Wed Jul 22 07:49:44 CEST 2015


Hello,

Obj._meta.get_all_field_names() is what you are looking for.

Thank you.

On Thu, Jul 16, 2015 at 11:23 PM, Sunil Gupta <sunil at planmytour.in> wrote:

> Hi All
>
> how can I iterate through the columns for an object in model
>
> example
> for an given object of a model I want to print the verbose name and its
> value when the help_text in the model is not NULL.
>
> class Client(models.Model):
>     cli_clientid = models.CharField(primary_key=True, verbose_name =
> "Client Id", help_text= "This is help")
>     cli_client_type = models.CharField(max_length=4, verbose_name =
> "Client Type", help_text= "")
>
> Assume Test_Client_Id is the value of cli_clientid os respective object
>
> for each column in Obj
>      if column.help_text != "" :
>               print "The column ", column.verbose_name, " has value ",
> column.value
>
> expected output
>
> The column Client Id has value Test_Client_Id
>
> Thanks
> Sunil
> 9008524726
>
>
> _______________________________________________
> Chennaipy mailing list
> Chennaipy at python.org
> https://mail.python.org/mailman/listinfo/chennaipy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chennaipy/attachments/20150722/b551b654/attachment.html>


More information about the Chennaipy mailing list