Thursday, May 6, 2010

values() and GenericRelation

Hello,
I need to put into a template some fields of my model, but not all the
fields, it is better to specify which fields to pass.
Then, I use something like:

MyModel.objects.values('id', 'field1__name', 'field2',
'field3__value', 'my_custom_set')

But, 'my_custom_field' is a GenericRelation field, and I can't specify
it as parameter of the QuerySet values() method.
The error is:

Exception Type: FieldError
Exception Value: Invalid field name: 'my_custom_set'

Note I've already read that values() method doesn't return anything
for M2M fields attributes, but not sure if a GenericRelation is really
a m2m field relationship.
(http://docs.djangoproject.com/en/1.1/ref/models/querysets/#values-fields)

However, if I give to the template the full list of fields, it works,
for example, using:

MyModel.objects.all()

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?

Thanks your comments, and if it's not clear, please tell me, i'll try
to clarify my problem.

Regards,
Caio

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate