Wednesday, June 26, 2013

Re: How i can get real value of ForeingKey?

It's because class A doesn't have unicode defined, so by default primary key is used to present objects of the class A.  Create unicode function and return any field you need.

class A (models.Model):
     field1 = models.CharField (max_length = 10)

     def __unicode__(self):
        return self.field1


On Wednesday, June 26, 2013 3:47:09 PM UTC+2, Mário Idival wrote:
Good morning,
Guys, how can I get the real value of a ForeignKey?
Examples:
class A (models.Model):
     field1 = models.CharField (max_length = 10)

class B (models.Model):
      field_b1 = models.CharField (max_length = 10)
      a_field = models.ForeingKey (A)

right, now imagine that on the bench, table A has saved:
field1 = "world"
and B is saved in the table:
field_b1 = "hello"
a_field = 1

Well, how can I get the real value of a_field (which is world)? But there's a catch, I wanna do this for the entire table B, if there is more fields saved in the bank.


Sincerely,

--
Mário Idival

Twitter @marioigd
Facebookmario.idival
User Linux : #554446
Skype: marioidival

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment