mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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 '<script type="text/javascript">addEvent(window, "load", function(e) {' \ | ||||
|               ' SelectFilter.init("id_%s", "%s", %s, "%s"); });</script>\n' % ( | ||||
|               f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX) | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user