From e3e271ff921ba333f03dafe0306b57c59eb9d7e2 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 10 Apr 2006 03:32:38 +0000 Subject: [PATCH] Fixed #1600 -- Renamed ManyToMany to ManyToManyRel so people get a clearer error if they use ManyToMany instead of ManyToManyField git-svn-id: http://code.djangoproject.com/svn/django/trunk@2648 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/templatetags/admin_modify.py | 4 ++-- django/contrib/admin/views/main.py | 6 +++--- django/core/management.py | 2 +- django/core/meta/__init__.py | 2 +- django/core/meta/fields.py | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index 4f161e2b7f..eccc377eac 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -103,7 +103,7 @@ class FieldWrapper(object): return self.field.blank and ' class="optional"' or '' def use_raw_id_admin(self): - return isinstance(self.field.rel, (meta.ManyToOne, meta.ManyToMany)) \ + return isinstance(self.field.rel, (meta.ManyToOne, meta.ManyToManyRel)) \ and self.field.rel.raw_id_admin class FormFieldCollectionWrapper(object): @@ -191,7 +191,7 @@ auto_populated_field_script = register.simple_tag(auto_populated_field_script) def filter_interface_script_maybe(bound_field): f = bound_field.field - if f.rel and isinstance(f.rel, meta.ManyToMany) and f.rel.filter_interface: + if f.rel and isinstance(f.rel, meta.ManyToManyRel) and f.rel.filter_interface: return '\n' % ( f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 4aa31d81ae..17575e5e7d 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -247,7 +247,7 @@ def change_list(request, app_label, module_name): 'admin/change_list'], context_instance=c) change_list = staff_member_required(change_list) -use_raw_id_admin = lambda field: isinstance(field.rel, (meta.ManyToOne, meta.ManyToMany)) and field.rel.raw_id_admin +use_raw_id_admin = lambda field: isinstance(field.rel, (meta.ManyToOne, meta.ManyToManyRel)) and field.rel.raw_id_admin def get_javascript_imports(opts,auto_populated_fields, ordered_objects, field_sets): # Put in any necessary JavaScript imports. @@ -285,7 +285,7 @@ class AdminBoundField(BoundField): self.raw_id_admin = use_raw_id_admin(field) self.is_date_time = isinstance(field, meta.DateTimeField) self.is_file_field = isinstance(field, meta.FileField) - self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin + self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToManyRel) and field.rel.to.admin self.hidden = isinstance(self.field, meta.AutoField) self.first = False @@ -310,7 +310,7 @@ class AdminBoundField(BoundField): if isinstance(self.field.rel, meta.ManyToOne): func_name = 'get_%s' % self.field.name self._display = self._fetch_existing_display(func_name) - elif isinstance(self.field.rel, meta.ManyToMany): + elif isinstance(self.field.rel, meta.ManyToManyRel): func_name = 'get_%s_list' % self.field.rel.singular self._display = ", ".join([str(obj) for obj in self._fetch_existing_display(func_name)]) self._display_filled = True diff --git a/django/core/management.py b/django/core/management.py index 00ef9ab706..15f570c57b 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -781,7 +781,7 @@ def get_validation_errors(outfile): except meta.FieldDoesNotExist: e.add(opts, '"unique_together" refers to %s, a field that doesn\'t exist. Check your syntax.' % field_name) else: - if isinstance(f.rel, meta.ManyToMany): + if isinstance(f.rel, meta.ManyToManyRel): e.add(opts, '"unique_together" refers to %s. ManyToManyFields are not supported in unique_together.' % f.name) return len(e.errors) diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 99849d038f..b99c15a833 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -385,7 +385,7 @@ class Options: # Move many-to-many related fields from self.fields into self.many_to_many. self.fields, self.many_to_many = [], [] for field in (fields or []): - if field.rel and isinstance(field.rel, ManyToMany): + if field.rel and isinstance(field.rel, ManyToManyRel): self.many_to_many.append(field) else: self.fields.append(field) diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py index b7e09067e7..926b306318 100644 --- a/django/core/meta/fields.py +++ b/django/core/meta/fields.py @@ -123,7 +123,7 @@ class Field(object): self.radio_admin = radio_admin self.help_text = help_text self.db_column = db_column - if rel and isinstance(rel, ManyToMany): + if rel and isinstance(rel, ManyToManyRel): if rel.raw_id_admin: self.help_text = string_concat(self.help_text, gettext_lazy(' Separate multiple IDs with commas.')) @@ -742,7 +742,7 @@ class ForeignKey(Field): class ManyToManyField(Field): def __init__(self, to, **kwargs): kwargs['verbose_name'] = kwargs.get('verbose_name', to._meta.verbose_name_plural) - kwargs['rel'] = ManyToMany(to, kwargs.pop('singular', None), + kwargs['rel'] = ManyToManyRel(to, kwargs.pop('singular', None), num_in_admin=kwargs.pop('num_in_admin', 0), related_name=kwargs.pop('related_name', None), filter_interface=kwargs.pop('filter_interface', None), @@ -842,7 +842,7 @@ class ManyToOne: "Returns the Field in the 'to' object to which this relationship is tied." return self.to.get_field(self.field_name) -class ManyToMany: +class ManyToManyRel: def __init__(self, to, singular=None, num_in_admin=0, related_name=None, filter_interface=None, limit_choices_to=None, raw_id_admin=False): self.to = to._meta @@ -853,7 +853,7 @@ class ManyToMany: self.limit_choices_to = limit_choices_to or {} self.edit_inline = False self.raw_id_admin = raw_id_admin - assert not (self.raw_id_admin and self.filter_interface), "ManyToMany relationships may not use both raw_id_admin and filter_interface" + assert not (self.raw_id_admin and self.filter_interface), "ManyToManyRels may not use both raw_id_admin and filter_interface" class OneToOne(ManyToOne): def __init__(self, to, field_name, num_in_admin=0, edit_inline=False,