Unfortunately you've missed the same thing that every other person who's said the same thing has missed:

Admin forms, fieldsets, and filter_horizontal.

Django provides implicit reverse models, but they are not the same, and do not act the same as explicit ManyToMany relationships. I'll be very very happy, if I'm wrong, but so far.. To get a consistent admin view on both models, I apparently have to do it with explicit relationships.

On 2/4/11 4:12 PM, Michael wrote:
A ManyToMany field on one model will automatically place a corresponding
field in the other model that provides the reverse lookup.  For example,
if you have:

class HostGroup(models.Model):
      hosts = models.ManyToManyField('Host', blank=True, null=True,
                          related_name='host_groups',
                          db_table='config_host_hostgroups')

Then Host.host_groups would be a RelatedManager that will give you all
instances of HostGroup that are mapped to that Host. Letting you do
something like this:

my_host = Host.objects.all()[0]
my_groups = host.host_groups.all()

Notice that the 'related_name' parameter of a ManyToManyField is the
name of the attribute placed on the other model for the reverse
reference.



--
--
Mike Lindsey

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to