Re: Nice representation for Querying with ForeignKeys

2008-08-28 Thread Abe

If B has __unicode__ defined and the output is printed somehow, then
it should display
the output of __unicode__ whenever this happens.

If this isn't being used in a string somehow, then just run a loop
over the query set.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Nice representation for Querying with ForeignKeys

2008-08-27 Thread johnny

Hi,
  This should be a simple question but I just couldn't seem to find
the answer.  I have a simple 2 model relationship:

class B(models.Model):
bfield = models.CharField(...)

class A(models.Model):
afield = models.CharField(...)
bfieldFK  = models.ForeignKey(B)

what is the best way to query for example A.objects.filter(pk=1) such
that the representation is something like:
[{'id':1, 'afield':'a', 'bfield':'b'}]

and not:
[{'id':1, 'afield':'a', 'bfieldFK_id':2}]  # eg. using .values()

the objective is to serialize it (if it makes a difference), but the
key idea is to have the output fields represented as if B were never a
separate model.

thank you so much,
Johnny
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Nice representation for Querying with ForeignKeys

2008-08-27 Thread johnny

Hi,
  This should be a simple question but I just couldn't seem to find
the answer.  I have a simple 2 model relationship:

class B(models.Model):
bfield = models.CharField(...)

class A(models.Model):
afield = models.CharField(...)
modelB  = models.ForeignKey(B)

what is the best way to query for example A.objects.filter(pk=1) such
that the representation is something like:
[{'id':1, 'afield':'a', 'bfield':'b'}]

and not:
[{'id':1, 'afield':'a', 'bfield_id':2}]  # eg. using .values()

the objective is to serialize it (if it makes a difference), but the
key idea is to have the output fields represented as if B were never a
separate model.

thank you so much,
Johnny


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---