On Wed, Nov 4, 2009 at 10:50 PM, DavodM <david.mcc...@gmail.com> wrote:
>
> Hello,
>
> I have a many to many relationship between 'Projects' and 'Tags' in my
> app.
>
> In the admin screen I would like to be able to use the
> filter_horizontal interface for adding/editing from both sides of the
> relationship but I can only seem to get it for one or the other.
>
> I have tried the solution here
>
> http://stackoverflow.com/questions/1339409/,
>
> Which involves creating the projects_tags table manually in models
> using a foreign key to each side (as you would do manually in SQL) and
> then referring to it as the model for an AdminInline.
> This allows me to display an inline to edit both sides of the
> relationship but I don't seem to be able to display the inlines as
> filter_horizontal because the relationships are now one to many.

You're getting two different terms confused here.

filter_horizontal is a single-widget representation for a m2m field.
This can't be applied in the reverse direction - an m2m widget is only
automatically generated on model that defines the relation.

On the other hand, Inlines are a way of representing objects related
to a given object by displaying a sub-form for each related object. In
the workaround you describe, the 'related object' is the row
describing the intermediate table - i.e., the 'relationship' is
actually the object, not the object on the other side of the m2m.

> I have also tried a different approach from the documentation here
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-models
>
> Which says to use Tag.projects.through as the model for the
> AdminInline
> But I get an error saying that Tag.projects.through does not exist. (I
> have checked and the SQL for the sqlite database and it is adding the
> projects_tags table).
>
> So either I would like a way to display an inline from a many to many
> relationship as filter_horizontal, or I need help getting the through
> attribute to work.

The through attribute was added last night to the trunk version of
Django. Unfortunately, I forgot to add the "new in development
version" marker to the documentation. I've made the change to the
documentation source; it should be updated online shortly.

However, as noted previously - the through model won't help you get
the filter_horizontal widget. The through model is just a cleaner way
of doing an Inline for m2m relations.

If you want to have a filter_horizontal widget for the reverse
direction of an m2m relation, you will need to define a custom
ModelForm that defines a widget for the reverse relation, and provide
that form to the ModelAdmin definition.

Yours,
Russ Magee %-)

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

Reply via email to