[BangPypers] How to iterate through columns in Model

Sunil Gupta sunil at planmytour.in
Thu Jul 16 19:51:19 CEST 2015


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


More information about the BangPypers mailing list