On Wed, 26 Jun 2013 10:47:09 -0300
Mário Idival <marioidi...@gmail.com> 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.
> 

Real value of a_field is an object instance type of the class (model) A.

So there is no magic "value". Even you see visible one field in your model 
(field1) your model actually contains already two fields: id and field1. In 
your case field1 can contain any 10 character string.

How you want to represent your related object is totally a different story and 
there is not single correct answer - it all depends how you want to represent 
it.

-- 

Jani Tiainen

"Impossible just takes a little longer"

-- 
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+unsubscr...@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.


Reply via email to