Django

Code

root/django/trunk/django/db/models/related.py

Revision 8616, 2.0 kB (checked in by gwilson, 3 months ago)

Removed oldforms, validators, and related code:

  • Removed Manipulator, AutomaticManipulator, and related classes.
  • Removed oldforms specific bits from model fields:
    • Removed validator_list and core arguments from constructors.
    • Removed the methods:
      • get_manipulator_field_names
      • get_manipulator_field_objs
      • get_manipulator_fields
      • get_manipulator_new_data
      • prepare_field_objs_and_params
      • get_follow
    • Renamed flatten_data method to value_to_string for better alignment with its use by the serialization framework, which was the only remaining code using flatten_data.
  • Removed oldforms methods from django.db.models.Options class: get_followed_related_objects, get_data_holders, get_follow, and has_field_type.
  • Removed oldforms-admin specific options from django.db.models.fields.related classes: num_in_admin, min_num_in_admin, max_num_in_admin, num_extra_on_change, and edit_inline.
  • Serialization framework
    • Serializer.get_string_value now calls the model fields' renamed value_to_string methods.
    • Removed a special-casing of models.DateTimeField in core.serializers.base.Serializer.get_string_value that's handled by django.db.models.fields.DateTimeField.value_to_string.
  • Removed django.core.validators:
    • Moved ValidationError exception to django.core.exceptions.
    • For the couple places that were using validators, brought over the necessary code to maintain the same functionality.
  • Introduced a SlugField? form field for validation and to compliment the SlugField? model field (refs #8040).
  • Removed an oldforms-style model creation hack (refs #2160).
  • Property svn:eol-style set to native
Line 
1 class BoundRelatedObject(object):
2     def __init__(self, related_object, field_mapping, original):
3         self.relation = related_object
4         self.field_mappings = field_mapping[related_object.name]
5
6     def template_name(self):
7         raise NotImplementedError
8
9     def __repr__(self):
10         return repr(self.__dict__)
11
12 class RelatedObject(object):
13     def __init__(self, parent_model, model, field):
14         self.parent_model = parent_model
15         self.model = model
16         self.opts = model._meta
17         self.field = field
18         self.name = '%s:%s' % (self.opts.app_label, self.opts.module_name)
19         self.var_name = self.opts.object_name.lower()
20
21     def get_db_prep_lookup(self, lookup_type, value):
22         # Defer to the actual field definition for db prep
23         return self.field.get_db_prep_lookup(lookup_type, value)
24
25     def editable_fields(self):
26         "Get the fields in this class that should be edited inline."
27         return [f for f in self.opts.fields + self.opts.many_to_many if f.editable and f != self.field]
28
29     def __repr__(self):
30         return "<RelatedObject: %s related to %s>" % (self.name, self.field.name)
31
32     def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject):
33         return bound_related_object_class(self, field_mapping, original)
34
35     def get_accessor_name(self):
36         # This method encapsulates the logic that decides what name to give an
37         # accessor descriptor that retrieves related many-to-one or
38         # many-to-many objects. It uses the lower-cased object_name + "_set",
39         # but this can be overridden with the "related_name" option.
40         if self.field.rel.multiple:
41             # If this is a symmetrical m2m relation on self, there is no reverse accessor.
42             if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model:
43                 return None
44             return self.field.rel.related_name or (self.opts.object_name.lower() + '_set')
45         else:
46             return self.field.rel.related_name or (self.opts.object_name.lower())
Note: See TracBrowser for help on using the browser.