2007/9/6, David Larlet <[EMAIL PROTECTED]>:
> Hi all,
>
> Before submitting a bug I'd like to be sure that it hadn't been done
> intentionally, here is the issue:
>
> I had a model with two GenericForeignKeys which where defined like that:
>
> class Foo(models.Model):
> item = generic.GenericForeignKey(ct_field="item_content_type",
> fk_field="item_object_id")
> item_content_type = models.ForeignKey(ContentType, related_name="item")
> item_object_id = models.IntegerField()
>
> step = generic.GenericForeignKey(ct_field="step_content_type",
> fk_field="step_object_id")
> step_content_type = models.ForeignKey(ContentType, related_name="step")
> step_object_id = models.IntegerField()
>
> It works but now I want to retrieve my Foo object from the Bar model
> for example:
>
> class Bar(models.Model):
> foo = generic.GenericRelation(Foo)
>
> Here I can't access the foo attribute from a Bar instance because the
> GenericRelation do not seemed to handle specific ct_field and fk_field
> in GenericForeignKey. I suspect this part of the GenericRelation's
> code with hard-coded "object_id" name:
>
> self.object_id_field_name = kwargs.pop("object_id_field", "object_id")
> self.content_type_field_name = kwargs.pop("content_type_field",
> "content_type")
>
> Any thought before I hack my django in order to find a patch?
Ok, thanks to a previous message I found the solution:
http://groups.google.com/group/django-developers/browse_thread/thread/5c440115389b56a6/3139d2e61b81b908
I need to specify fields in my GenericRelation definition:
foo = generic.GenericRelation(Foo,
object_id_field='item_object_id',
content_type_field='item_content_type')
But I agree with webograph that it violate the DRY principle...
David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---