I have in my model something like this: class Person(models.Model): field1 = ForeignKey(City) field2 = models.TextField() field3 = ForeignKey(Type) photos = ImagingField() photos_set = generic.GenericRelation(Image) ....
class City(models.Model): name = CharField() class Type(models.Model): value = CharField() Then I wanto to get in my template the value of Person.field1 but as "name" not the "id". The same with field3, I want the "value" not the "id". Maybe is a silly question, but doesn't work if I call Person.field1.name. Finally, I also want to use in my template the first value of the photos_set (in my previous email i refered to this as "my_custom_set"). But again, I can specify this field as values() method's parameter. Hope it explains better the situation. Thanks, Caio On Fri, May 7, 2010 at 6:26 AM, Nuno Maltez <nuno.li...@gmail.com> wrote: >> MyModel.objects.values('id', 'field1__name', 'field2', >> 'field3__value', 'my_custom_set') > > ... > >> I could use all() result, but I must use the ForeingKey values of the >> field1 and field3, so I don't know how to get its values if it not the >> way I said before. >> >> How can I resolve this? > > I can't help you on how to use the values method, but can't you just access > obj.field1.name to get the name of the related object in field 1 (or > obj.field1.id to get its id). > > > HTH, > Nuno > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.