Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Renamed ManyToOne to ManyToOneRel to be consistent with ManyToManyRel

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2649 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b8d8aca5fd810cd5906d382e5d2c6d04ed63dffb 1 parent e3e271f
Adrian Holovaty authored April 10, 2006
4  django/contrib/admin/templatetags/admin_list.py
@@ -87,7 +87,7 @@ def result_headers(cl):
87 87
             # Non-field list_display values don't get ordering capability.
88 88
             yield {"text": header}
89 89
         else:
90  
-            if isinstance(f.rel, meta.ManyToOne) and f.null:
  90
+            if isinstance(f.rel, meta.ManyToOneRel) and f.null:
91 91
                 yield {"text": f.verbose_name}
92 92
             else:
93 93
                 th_classes = []
@@ -124,7 +124,7 @@ def items_for_result(cl, result):
124 124
         else:
125 125
             field_val = getattr(result, f.attname)
126 126
 
127  
-            if isinstance(f.rel, meta.ManyToOne):
  127
+            if isinstance(f.rel, meta.ManyToOneRel):
128 128
                 if field_val is not None:
129 129
                     result_repr = getattr(result, 'get_%s' % f.name)()
130 130
                 else:
2  django/contrib/admin/templatetags/admin_modify.py
@@ -103,7 +103,7 @@ def header_class_attribute(self):
103 103
         return self.field.blank and ' class="optional"' or ''
104 104
 
105 105
     def use_raw_id_admin(self):
106  
-         return isinstance(self.field.rel, (meta.ManyToOne, meta.ManyToManyRel)) \
  106
+         return isinstance(self.field.rel, (meta.ManyToOneRel, meta.ManyToManyRel)) \
107 107
             and self.field.rel.raw_id_admin
108 108
 
109 109
 class FormFieldCollectionWrapper(object):
12  django/contrib/admin/views/main.py
@@ -174,7 +174,7 @@ def get_ordering(self):
174 174
                 except meta.FieldDoesNotExist:
175 175
                     pass
176 176
                 else:
177  
-                    if not isinstance(f.rel, meta.ManyToOne) or not f.null:
  177
+                    if not isinstance(f.rel, meta.ManyToOneRel) or not f.null:
178 178
                         order_field = f.name
179 179
             except (IndexError, ValueError):
180 180
                 pass # Invalid ordering specified. Just use the default.
@@ -199,7 +199,7 @@ def get_lookup_params(self):
199 199
         except meta.FieldDoesNotExist:
200 200
             pass
201 201
         else:
202  
-            if isinstance(lookup_opts.get_field(order_field).rel, meta.ManyToOne):
  202
+            if isinstance(lookup_opts.get_field(order_field).rel, meta.ManyToOneRel):
203 203
                 f = lookup_opts.get_field(order_field)
204 204
                 rel_ordering = f.rel.to.ordering and f.rel.to.ordering[0] or f.rel.to.pk.column
205 205
                 lookup_order_field = '%s.%s' % (f.rel.to.db_table, rel_ordering)
@@ -214,7 +214,7 @@ def get_lookup_params(self):
214 214
                 except meta.FieldDoesNotExist:
215 215
                     pass
216 216
                 else:
217  
-                    if isinstance(f.rel, meta.ManyToOne):
  217
+                    if isinstance(f.rel, meta.ManyToOneRel):
218 218
                         lookup_params['select_related'] = True
219 219
                         break
220 220
         lookup_params['order_by'] = ((order_type == 'desc' and '-' or '') + lookup_order_field,)
@@ -247,7 +247,7 @@ def change_list(request, app_label, module_name):
247 247
                                'admin/change_list'], context_instance=c)
248 248
 change_list = staff_member_required(change_list)
249 249
 
250  
-use_raw_id_admin = lambda field: isinstance(field.rel, (meta.ManyToOne, meta.ManyToManyRel)) and field.rel.raw_id_admin
  250
+use_raw_id_admin = lambda field: isinstance(field.rel, (meta.ManyToOneRel, meta.ManyToManyRel)) and field.rel.raw_id_admin
251 251
 
252 252
 def get_javascript_imports(opts,auto_populated_fields, ordered_objects, field_sets):
253 253
 # Put in any necessary JavaScript imports.
@@ -285,7 +285,7 @@ def __init__(self, field, field_mapping, original):
285 285
         self.raw_id_admin = use_raw_id_admin(field)
286 286
         self.is_date_time = isinstance(field, meta.DateTimeField)
287 287
         self.is_file_field = isinstance(field, meta.FileField)
288  
-        self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToManyRel) and field.rel.to.admin
  288
+        self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOneRel) or isinstance(field.rel, meta.ManyToManyRel) and field.rel.to.admin
289 289
         self.hidden = isinstance(self.field, meta.AutoField)
290 290
         self.first = False
291 291
 
@@ -307,7 +307,7 @@ def _fill_existing_display(self):
307 307
         if getattr(self, '_display_filled', False):
308 308
             return
309 309
         # HACK
310  
-        if isinstance(self.field.rel, meta.ManyToOne):
  310
+        if isinstance(self.field.rel, meta.ManyToOneRel):
311 311
              func_name = 'get_%s' % self.field.name
312 312
              self._display = self._fetch_existing_display(func_name)
313 313
         elif isinstance(self.field.rel, meta.ManyToManyRel):
12  django/core/meta/__init__.py
@@ -494,7 +494,7 @@ def get_all_related_objects(self):
494 494
                 # subsequently loaded object with related links will override this
495 495
                 # relationship we're adding.
496 496
                 link_field = copy.copy(relatedlinks.RelatedLink._meta.get_field('object_id'))
497  
-                link_field.rel = ManyToOne(self.get_model_module().Klass, 'id',
  497
+                link_field.rel = ManyToOneRel(self.get_model_module().Klass, 'id',
498 498
                     num_in_admin=3, min_num_in_admin=3, edit_inline=TABULAR,
499 499
                     lookup_overrides={
500 500
                         'content_type__package__label__exact': self.app_label,
@@ -748,7 +748,7 @@ def __new__(cls, name, bases, attrs):
748 748
                 f.rel.field_name = f.rel.field_name or f.rel.to.pk.name
749 749
             # Add "get_thingie" methods for many-to-one related objects.
750 750
             # EXAMPLES: Choice.get_poll(), Story.get_dateline()
751  
-            if isinstance(f.rel, ManyToOne):
  751
+            if isinstance(f.rel, ManyToOneRel):
752 752
                 func = curry(method_get_many_to_one, f)
753 753
                 func.__doc__ = "Returns the associated `%s.%s` object." % (f.rel.to.app_label, f.rel.to.module_name)
754 754
                 attrs['get_%s' % f.name] = func
@@ -946,7 +946,7 @@ def __repr__(self):
946 946
 def method_init(opts, self, *args, **kwargs):
947 947
     if kwargs:
948 948
         for f in opts.fields:
949  
-            if isinstance(f.rel, ManyToOne):
  949
+            if isinstance(f.rel, ManyToOneRel):
950 950
                 try:
951 951
                     # Assume object instance was passed in.
952 952
                     rel_obj = kwargs.pop(f.name)
@@ -1927,7 +1927,7 @@ def manipulator_flatten_data(opts, klass, add, change, self):
1927 1927
 def manipulator_validator_unique_together(field_name_list, opts, self, field_data, all_data):
1928 1928
     from django.utils.text import get_text_list
1929 1929
     field_list = [opts.get_field(field_name) for field_name in field_name_list]
1930  
-    if isinstance(field_list[0].rel, ManyToOne):
  1930
+    if isinstance(field_list[0].rel, ManyToOneRel):
1931 1931
         kwargs = {'%s__%s__iexact' % (field_name_list[0], field_list[0].rel.field_name): field_data}
1932 1932
     else:
1933 1933
         kwargs = {'%s__iexact' % field_name_list[0]: field_data}
@@ -1940,7 +1940,7 @@ def manipulator_validator_unique_together(field_name_list, opts, self, field_dat
1940 1940
             # This will be caught by another validator, assuming the field
1941 1941
             # doesn't have blank=True.
1942 1942
             return
1943  
-        if isinstance(f.rel, ManyToOne):
  1943
+        if isinstance(f.rel, ManyToOneRel):
1944 1944
             kwargs['%s__pk' % f.name] = field_val
1945 1945
         else:
1946 1946
             kwargs['%s__iexact' % f.name] = field_val
@@ -1962,7 +1962,7 @@ def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_t
1962 1962
     if date_val is None:
1963 1963
         return # Date was invalid. This will be caught by another validator.
1964 1964
     lookup_kwargs = {'%s__year' % date_field.name: date_val.year}
1965  
-    if isinstance(from_field.rel, ManyToOne):
  1965
+    if isinstance(from_field.rel, ManyToOneRel):
1966 1966
         lookup_kwargs['%s__pk' % from_field.name] = field_data
1967 1967
     else:
1968 1968
         lookup_kwargs['%s__iexact' % from_field.name] = field_data
14  django/core/meta/fields.py
@@ -47,7 +47,7 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
47 47
 
48 48
 def manipulator_validator_unique(f, opts, self, field_data, all_data):
49 49
     "Validates that the value is unique for this field."
50  
-    if f.rel and isinstance(f.rel, ManyToOne):
  50
+    if f.rel and isinstance(f.rel, ManyToOneRel):
51 51
         lookup_type = '%s__%s__exact' % (f.name, f.rel.get_related_field().name)
52 52
     else:
53 53
         lookup_type = '%s__exact' % f.name
@@ -133,7 +133,7 @@ def __init__(self, verbose_name=None, name=None, primary_key=False,
133 133
 
134 134
         # Set db_index to True if the field has a relationship and doesn't explicitly set db_index.
135 135
         if db_index is None:
136  
-            if isinstance(rel, OneToOne) or isinstance(rel, ManyToOne):
  136
+            if isinstance(rel, OneToOne) or isinstance(rel, ManyToOneRel):
137 137
                 self.db_index = True
138 138
             else:
139 139
                 self.db_index = False
@@ -152,7 +152,7 @@ def set_name(self, name):
152 152
         self.attname, self.column = self.get_attname_column()
153 153
 
154 154
     def get_attname_column(self):
155  
-        if isinstance(self.rel, ManyToOne):
  155
+        if isinstance(self.rel, ManyToOneRel):
156 156
             attname = '%s_id' % self.name
157 157
         else:
158 158
             attname = self.name
@@ -222,7 +222,7 @@ def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=
222 222
         params = {'validator_list': self.validator_list[:]}
223 223
         if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
224 224
             params['maxlength'] = self.maxlength
225  
-        if isinstance(self.rel, ManyToOne):
  225
+        if isinstance(self.rel, ManyToOneRel):
226 226
             params['member_name'] = name_prefix + self.attname
227 227
             if self.rel.raw_id_admin:
228 228
                 field_objs = self.get_manipulator_field_objs()
@@ -698,7 +698,7 @@ def __init__(self, to, to_field=None, **kwargs):
698 698
             warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.")
699 699
             kwargs['edit_inline'] = kwargs.pop('edit_inline_type')
700 700
 
701  
-        kwargs['rel'] = ManyToOne(to, to_field,
  701
+        kwargs['rel'] = ManyToOneRel(to, to_field,
702 702
             num_in_admin=kwargs.pop('num_in_admin', 3),
703 703
             min_num_in_admin=kwargs.pop('min_num_in_admin', None),
704 704
             max_num_in_admin=kwargs.pop('max_num_in_admin', None),
@@ -821,7 +821,7 @@ def __init__(self, to, to_field=None, **kwargs):
821 821
         kwargs['primary_key'] = True
822 822
         IntegerField.__init__(self, **kwargs)
823 823
 
824  
-class ManyToOne:
  824
+class ManyToOneRel:
825 825
     def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None,
826 826
         max_num_in_admin=None, num_extra_on_change=1, edit_inline=False,
827 827
         related_name=None, limit_choices_to=None, lookup_overrides=None, raw_id_admin=False):
@@ -855,7 +855,7 @@ def __init__(self, to, singular=None, num_in_admin=0, related_name=None,
855 855
         self.raw_id_admin = raw_id_admin
856 856
         assert not (self.raw_id_admin and self.filter_interface), "ManyToManyRels may not use both raw_id_admin and filter_interface"
857 857
 
858  
-class OneToOne(ManyToOne):
  858
+class OneToOne(ManyToOneRel):
859 859
     def __init__(self, to, field_name, num_in_admin=0, edit_inline=False,
860 860
         related_name=None, limit_choices_to=None, lookup_overrides=None,
861 861
         raw_id_admin=False):
2  django/models/__init__.py
@@ -32,7 +32,7 @@
32 32
                 func = curry(meta.method_get_related, 'get_object', rel_mod, related.field)
33 33
                 func.__doc__ = "Returns the associated `%s.%s` object." % (related.opts.app_label, related.opts.module_name)
34 34
                 setattr(klass, 'get_%s' % rel_obj_name, func)
35  
-            elif isinstance(related.field.rel, meta.ManyToOne):
  35
+            elif isinstance(related.field.rel, meta.ManyToOneRel):
36 36
                 # Add "get_thingie" methods for many-to-one related objects.
37 37
                 # EXAMPLE: Poll.get_choice()
38 38
                 func = curry(meta.method_get_related, 'get_object', rel_mod, related.field)

0 notes on commit b8d8aca

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