diff options
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/__init__.py | 2 | ||||
| -rw-r--r-- | django/db/models/base.py | 5 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 33 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 77 | ||||
| -rw-r--r-- | django/db/models/manipulators.py | 7 | ||||
| -rw-r--r-- | django/db/models/options.py | 75 |
6 files changed, 35 insertions, 164 deletions
diff --git a/django/db/models/__init__.py b/django/db/models/__init__.py index 86763d99f9..bd6cc3542d 100644 --- a/django/db/models/__init__.py +++ b/django/db/models/__init__.py @@ -5,7 +5,7 @@ from django.db import connection from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models from django.db.models.query import Q from django.db.models.manager import Manager -from django.db.models.base import Model, AdminOptions +from django.db.models.base import Model from django.db.models.fields import * from django.db.models.fields.subclassing import SubfieldBase from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel, TABULAR, STACKED diff --git a/django/db/models/base.py b/django/db/models/base.py index 757f2378ce..e2ba49ee8c 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -15,7 +15,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField from django.db.models.query import delete_objects, Q, CollectedObjects -from django.db.models.options import Options, AdminOptions +from django.db.models.options import Options from django.db import connection, transaction from django.db.models import signals from django.db.models.loading import register_models, get_model @@ -137,9 +137,6 @@ class ModelBase(type): return get_model(new_class._meta.app_label, name, False) def add_to_class(cls, name, value): - if name == 'Admin': - assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value)) - value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')])) if hasattr(value, 'contribute_to_class'): value.contribute_to_class(cls, name) else: diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 713343cc15..879807d2d2 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -28,16 +28,10 @@ from django.utils import datetime_safe class NOT_PROVIDED: pass -# Values for filter_interface. -HORIZONTAL, VERTICAL = 1, 2 - # The values to use for "blank" in SelectFields. Will be appended to the start of most "choices" lists. BLANK_CHOICE_DASH = [("", "---------")] BLANK_CHOICE_NONE = [("", "None")] -# returns the <ul> class for a given radio_admin value -get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '') - class FieldDoesNotExist(Exception): pass @@ -85,10 +79,10 @@ class Field(object): def __init__(self, verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, core=False, rel=None, default=NOT_PROVIDED, - editable=True, serialize=True, prepopulate_from=None, - unique_for_date=None, unique_for_month=None, unique_for_year=None, - validator_list=None, choices=None, radio_admin=None, help_text='', - db_column=None, db_tablespace=None, auto_created=False): + editable=True, serialize=True, unique_for_date=None, + unique_for_month=None, unique_for_year=None, validator_list=None, + choices=None, help_text='', db_column=None, db_tablespace=None, + auto_created=False): self.name = name self.verbose_name = verbose_name self.primary_key = primary_key @@ -102,11 +96,9 @@ class Field(object): self.editable = editable self.serialize = serialize self.validator_list = validator_list or [] - self.prepopulate_from = prepopulate_from self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month self.unique_for_year = unique_for_year self._choices = choices or [] - self.radio_admin = radio_admin self.help_text = help_text self.db_column = db_column self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE @@ -294,11 +286,7 @@ class Field(object): params['max_length'] = self.max_length if self.choices: - if self.radio_admin: - field_objs = [oldforms.RadioSelectField] - params['ul_class'] = get_ul_class(self.radio_admin) - else: - field_objs = [oldforms.SelectField] + field_objs = [oldforms.SelectField] params['choices'] = self.get_choices_default() else: @@ -386,10 +374,7 @@ class Field(object): return first_choice + lst def get_choices_default(self): - if self.radio_admin: - return self.get_choices(include_blank=self.blank, blank_choice=BLANK_CHOICE_NONE) - else: - return self.get_choices() + return self.get_choices() def _get_val_from_obj(self, obj): if obj: @@ -1012,7 +997,11 @@ class NullBooleanField(Field): return [oldforms.NullBooleanField] def formfield(self, **kwargs): - defaults = {'form_class': forms.NullBooleanField} + defaults = { + 'form_class': forms.NullBooleanField, + 'required': not self.blank, + 'label': capfirst(self.verbose_name), + 'help_text': self.help_text} defaults.update(kwargs) return super(NullBooleanField, self).formfield(**defaults) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index a1977c07b4..594236b4c6 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1,6 +1,6 @@ from django.db import connection, transaction from django.db.models import signals, get_model -from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, get_ul_class, FieldDoesNotExist +from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist from django.db.models.related import RelatedObject from django.db.models.query_utils import QueryWrapper from django.utils.text import capfirst @@ -541,7 +541,7 @@ class ManyToOneRel(object): def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None, max_num_in_admin=None, num_extra_on_change=1, edit_inline=False, related_name=None, limit_choices_to=None, lookup_overrides=None, - raw_id_admin=False, parent_link=False): + parent_link=False): try: to._meta except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT @@ -554,7 +554,6 @@ class ManyToOneRel(object): limit_choices_to = {} self.limit_choices_to = limit_choices_to self.lookup_overrides = lookup_overrides or {} - self.raw_id_admin = raw_id_admin self.multiple = True self.parent_link = parent_link @@ -573,34 +572,29 @@ class OneToOneRel(ManyToOneRel): def __init__(self, to, field_name, num_in_admin=0, min_num_in_admin=None, max_num_in_admin=None, num_extra_on_change=None, edit_inline=False, related_name=None, limit_choices_to=None, lookup_overrides=None, - raw_id_admin=False, parent_link=False): + parent_link=False): # NOTE: *_num_in_admin and num_extra_on_change are intentionally # ignored here. We accept them as parameters only to match the calling # signature of ManyToOneRel.__init__(). super(OneToOneRel, self).__init__(to, field_name, num_in_admin, edit_inline=edit_inline, related_name=related_name, limit_choices_to=limit_choices_to, - lookup_overrides=lookup_overrides, raw_id_admin=raw_id_admin, - parent_link=parent_link) + lookup_overrides=lookup_overrides, parent_link=parent_link) self.multiple = False class ManyToManyRel(object): def __init__(self, to, num_in_admin=0, related_name=None, - filter_interface=None, limit_choices_to=None, raw_id_admin=False, symmetrical=True): + limit_choices_to=None, symmetrical=True): self.to = to self.num_in_admin = num_in_admin self.related_name = related_name - self.filter_interface = filter_interface if limit_choices_to is None: limit_choices_to = {} self.limit_choices_to = limit_choices_to self.edit_inline = False - self.raw_id_admin = raw_id_admin self.symmetrical = symmetrical self.multiple = True - assert not (self.raw_id_admin and self.filter_interface), "ManyToManyRels may not use both raw_id_admin and filter_interface" - class ForeignKey(RelatedField, Field): empty_strings_allowed = False def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): @@ -626,7 +620,6 @@ class ForeignKey(RelatedField, Field): related_name=kwargs.pop('related_name', None), limit_choices_to=kwargs.pop('limit_choices_to', None), lookup_overrides=kwargs.pop('lookup_overrides', None), - raw_id_admin=kwargs.pop('raw_id_admin', False), parent_link=kwargs.pop('parent_link', False)) Field.__init__(self, **kwargs) @@ -640,19 +633,11 @@ class ForeignKey(RelatedField, Field): def prepare_field_objs_and_params(self, manipulator, name_prefix): params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname} - if self.rel.raw_id_admin: - field_objs = self.get_manipulator_field_objs() - params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator)) + if self.null: + field_objs = [oldforms.NullSelectField] else: - if self.radio_admin: - field_objs = [oldforms.RadioSelectField] - params['ul_class'] = get_ul_class(self.radio_admin) - else: - if self.null: - field_objs = [oldforms.NullSelectField] - else: - field_objs = [oldforms.SelectField] - params['choices'] = self.get_choices_default() + field_objs = [oldforms.SelectField] + params['choices'] = self.get_choices_default() return field_objs, params def get_default(self): @@ -664,10 +649,7 @@ class ForeignKey(RelatedField, Field): def get_manipulator_field_objs(self): rel_field = self.rel.get_related_field() - if self.rel.raw_id_admin and not isinstance(rel_field, AutoField): - return rel_field.get_manipulator_field_objs() - else: - return [oldforms.IntegerField] + return [oldforms.IntegerField] def get_db_prep_save(self, value): if value == '' or value == None: @@ -679,15 +661,11 @@ class ForeignKey(RelatedField, Field): if not obj: # In required many-to-one fields with only one available choice, # select that one available choice. Note: For SelectFields - # (radio_admin=False), we have to check that the length of choices - # is *2*, not 1, because SelectFields always have an initial - # "blank" value. Otherwise (radio_admin=True), we check that the - # length is 1. - if not self.blank and (not self.rel.raw_id_admin or self.choices): + # we have to check that the length of choices is *2*, not 1, + # because SelectFields always have an initial "blank" value. + if not self.blank and self.choices: choice_list = self.get_choices_default() - if self.radio_admin and len(choice_list) == 1: - return {self.attname: choice_list[0][0]} - if not self.radio_admin and len(choice_list) == 2: + if len(choice_list) == 2: return {self.attname: choice_list[1][0]} return Field.flatten_data(self, follow, obj) @@ -704,7 +682,7 @@ class ForeignKey(RelatedField, Field): setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) def formfield(self, **kwargs): - defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()} + defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)} defaults.update(kwargs) return super(ForeignKey, self).formfield(**defaults) @@ -743,27 +721,17 @@ class ManyToManyField(RelatedField, Field): kwargs['rel'] = ManyToManyRel(to, num_in_admin=kwargs.pop('num_in_admin', 0), related_name=kwargs.pop('related_name', None), - filter_interface=kwargs.pop('filter_interface', None), limit_choices_to=kwargs.pop('limit_choices_to', None), - raw_id_admin=kwargs.pop('raw_id_admin', False), symmetrical=kwargs.pop('symmetrical', True)) self.db_table = kwargs.pop('db_table', None) - if kwargs["rel"].raw_id_admin: - kwargs.setdefault("validator_list", []).append(self.isValidIDList) Field.__init__(self, **kwargs) - if self.rel.raw_id_admin: - msg = ugettext_lazy('Separate multiple IDs with commas.') - else: - msg = ugettext_lazy('Hold down "Control", or "Command" on a Mac, to select more than one.') + msg = ugettext_lazy('Hold down "Control", or "Command" on a Mac, to select more than one.') self.help_text = string_concat(self.help_text, ' ', msg) def get_manipulator_field_objs(self): - if self.rel.raw_id_admin: - return [oldforms.RawIdAdminField] - else: - choices = self.get_choices_default() - return [curry(oldforms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)] + choices = self.get_choices_default() + return [curry(oldforms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)] def get_choices_default(self): return Field.get_choices(self, include_blank=False) @@ -812,14 +780,11 @@ class ManyToManyField(RelatedField, Field): new_data = {} if obj: instance_ids = [instance._get_pk_val() for instance in getattr(obj, self.name).all()] - if self.rel.raw_id_admin: - new_data[self.name] = u",".join([smart_unicode(id) for id in instance_ids]) - else: - new_data[self.name] = instance_ids + new_data[self.name] = instance_ids else: # In required many-to-many fields with only one available choice, # select that one available choice. - if not self.blank and not self.rel.edit_inline and not self.rel.raw_id_admin: + if not self.blank and not self.rel.edit_inline: choices_list = self.get_choices_default() if len(choices_list) == 1: new_data[self.name] = [choices_list[0][0]] @@ -861,7 +826,7 @@ class ManyToManyField(RelatedField, Field): setattr(instance, self.attname, data) def formfield(self, **kwargs): - defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()} + defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)} defaults.update(kwargs) # If initial is passed in, it's a list of related objects, but the # MultipleChoiceField takes a list of IDs. diff --git a/django/db/models/manipulators.py b/django/db/models/manipulators.py index 2d953260fb..4e6ddca26e 100644 --- a/django/db/models/manipulators.py +++ b/django/db/models/manipulators.py @@ -120,10 +120,7 @@ class AutomaticManipulator(oldforms.Manipulator): for f in self.opts.many_to_many: if self.follow.get(f.name, None): if not f.rel.edit_inline: - if f.rel.raw_id_admin: - new_vals = new_data.get(f.name, ()) - else: - new_vals = new_data.getlist(f.name) + new_vals = new_data.getlist(f.name) # First, clear the existing values. rel_manager = getattr(new_object, f.name) rel_manager.clear() @@ -220,8 +217,6 @@ class AutomaticManipulator(oldforms.Manipulator): for f in related.opts.many_to_many: if child_follow.get(f.name, None) and not f.rel.edit_inline: new_value = rel_new_data[f.attname] - if f.rel.raw_id_admin: - new_value = new_value[0] setattr(new_rel_obj, f.name, f.rel.to.objects.filter(pk__in=new_value)) if self.change: self.fields_changed.append('%s for %s "%s"' % (f.verbose_name, related.opts.verbose_name, new_rel_obj)) diff --git a/django/db/models/options.py b/django/db/models/options.py index a81a34d722..ffea6d5082 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -11,7 +11,6 @@ from django.db.models.fields.related import ManyToManyRel from django.db.models.fields import AutoField, FieldDoesNotExist from django.db.models.fields.proxy import OrderWrt from django.db.models.loading import get_models, app_cache_ready -from django.db.models import Manager from django.utils.translation import activate, deactivate_all, get_language, string_concat from django.utils.encoding import force_unicode, smart_str from django.utils.datastructures import SortedDict @@ -485,77 +484,3 @@ class Options(object): else: self._field_types[field_type] = False return self._field_types[field_type] - -class AdminOptions(object): - def __init__(self, fields=None, js=None, list_display=None, list_display_links=None, list_filter=None, - date_hierarchy=None, save_as=False, ordering=None, search_fields=None, - save_on_top=False, list_select_related=False, manager=None, list_per_page=100): - self.fields = fields - self.js = js or [] - self.list_display = list_display or ['__str__'] - self.list_display_links = list_display_links or [] - self.list_filter = list_filter or [] - self.date_hierarchy = date_hierarchy - self.save_as, self.ordering = save_as, ordering - self.search_fields = search_fields or [] - self.save_on_top = save_on_top - self.list_select_related = list_select_related - self.list_per_page = list_per_page - self.manager = manager or Manager() - - def get_field_sets(self, opts): - "Returns a list of AdminFieldSet objects for this AdminOptions object." - if self.fields is None: - field_struct = ((None, {'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)]}),) - else: - field_struct = self.fields - new_fieldset_list = [] - for fieldset in field_struct: - fs_options = fieldset[1] - classes = fs_options.get('classes', ()) - description = fs_options.get('description', '') - new_fieldset_list.append(AdminFieldSet(fieldset[0], classes, - opts.get_field, fs_options['fields'], description)) - return new_fieldset_list - - def contribute_to_class(self, cls, name): - cls._meta.admin = self - # Make sure the admin manager has access to the model - self.manager.model = cls - -class AdminFieldSet(object): - def __init__(self, name, classes, field_locator_func, line_specs, description): - self.name = name - self.field_lines = [AdminFieldLine(field_locator_func, line_spec) for line_spec in line_specs] - self.classes = classes - self.description = description - - def __repr__(self): - return "FieldSet: (%s, %s)" % (self.name, self.field_lines) - - def bind(self, field_mapping, original, bound_field_set_class): - return bound_field_set_class(self, field_mapping, original) - - def __iter__(self): - for field_line in self.field_lines: - yield field_line - - def __len__(self): - return len(self.field_lines) - -class AdminFieldLine(object): - def __init__(self, field_locator_func, linespec): - if isinstance(linespec, basestring): - self.fields = [field_locator_func(linespec)] - else: - self.fields = [field_locator_func(field_name) for field_name in linespec] - - def bind(self, field_mapping, original, bound_field_line_class): - return bound_field_line_class(self, field_mapping, original) - - def __iter__(self): - for field in self.fields: - yield field - - def __len__(self): - return len(self.fields) |
