On Sun, Jun 12, 2011 at 4:09 AM, Venkatraman S <[email protected]> wrote:
> On Sun, Jun 12, 2011 at 12:10 AM, Marc Aymerich <[email protected]> wrote:
>>
>> But, I'm wondering if django provides some generic mechanism to do the
>> invers relation? it is,given a Model_C object get all related Model_A
>> and Model_B objects.
>
> Like this :
> https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#reverse-generic-relations
Hi Venkatraman, with generic mechanism I wanted to say that the method
works for all models, maybe "dynamic mechanism" should be a better
name.
Anyway I write a method that does what i'm looking for.
get_related_FK(obj):
related_objects = []
for field in obj._meta.fields:
if field.__class__ is django.db.models.fields.related.ForeignKey:
related_objects.append(getattr(obj, field.name))
return related_objects
I just wondering if django ships with something like that, just for
avoid reinvent the wheel.
--
Marc
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.