Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added optional rel_name parameter to ManyToManyField, which makes it …

…possible to many-to-many-relate a single model to another model more than once. Also updated the model docs to reflect this

git-svn-id: http://code.djangoproject.com/svn/django/trunk@257 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bc5359f754f7afe6b4aa1eb4972c32a508b7fb55 1 parent 895d232
Adrian Holovaty authored July 20, 2005
5  django/core/meta.py
@@ -2049,10 +2049,11 @@ def get_manipulator_field_objs(self):
2049 2049
         return [formfields.IntegerField]
2050 2050
 
2051 2051
 class ManyToManyField(Field):
2052  
-    def __init__(self, to, **kwargs):
  2052
+    def __init__(self, to, rel_name=None, **kwargs):
2053 2053
         kwargs['name'] = kwargs.get('name', to._meta.module_name)
2054 2054
         kwargs['verbose_name'] = kwargs.get('verbose_name', to._meta.verbose_name_plural)
2055  
-        kwargs['rel'] = ManyToMany(to, to._meta.object_name.lower(),
  2055
+        rel_name = rel_name or to._meta.object_name.lower()
  2056
+        kwargs['rel'] = ManyToMany(to, rel_name,
2056 2057
             num_in_admin=kwargs.pop('num_in_admin', 0),
2057 2058
             related_name=kwargs.pop('related_name', None),
2058 2059
             filter_interface=kwargs.pop('filter_interface', None),
23  docs/model-api.txt
@@ -455,12 +455,17 @@ Field Types
455 455
 
456 456
     Many-to-many relations are a bit different from other fields.  First, they
457 457
     aren't actually a field per se, because they use a intermediary join table.
458  
-    Second, they don't take any of the same options as the rest of the fields.
459  
-    The only arguments taken are:
  458
+    Second, they don't take the same options as the rest of the fields. The
  459
+    only arguments taken are:
460 460
 
461 461
     =======================  ============================================================
462 462
     Argument                 Description
463 463
     =======================  ============================================================
  464
+    ``rel_name``             Use this if you have more than one
  465
+                             ``ManyToOneField`` s in the same model that relate
  466
+                             to the same model. Django will use ``rel_name`` in
  467
+                             the generated API.
  468
+
464 469
     ``related_name``         See the description of ``related_name`` in
465 470
                              ``ManyToOneField``, above.
466 471
 
@@ -471,7 +476,19 @@ Field Types
471 476
                              should the interface be stacked horizontally or
472 477
                              vertically).
473 478
 
474  
-    ``limit_choices_to``     See the description under ``ManyToOneField``, above.
  479
+    ``limit_choices_to``     See the description under ``ManyToOneField`` above.
  480
+
  481
+    ``name``                 An alphanumeric name for the relationship. If this
  482
+                             isn't provided, Django uses the ``module_name`` of
  483
+                             the related object.
  484
+
  485
+                             This is only really useful when you have a single
  486
+                             object that relates to the same object more than
  487
+                             once.
  488
+
  489
+    ``verbose_name``         A human-readable name for the object, singular. If
  490
+                             this isn't provided, Django uses the
  491
+                             ``verbose_name`` for the related object.
475 492
     =======================  ============================================================
476 493
 
477 494
 ``NullBooleanField``

0 notes on commit bc5359f

Please sign in to comment.
Something went wrong with that request. Please try again.