1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

newforms-admin: Backwards-incompatible change: Removed 'filter_interface' option on ManyToManyFields, in favor of 'filter_vertical' and 'filter_horizontal' options on 'class Admin'

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4458 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2007-02-02 20:37:10 +00:00
parent 92e3355493
commit af908e2e8d
5 changed files with 12 additions and 14 deletions

View File

@@ -111,6 +111,8 @@ class ModelAdmin(object):
fields = None fields = None
raw_id_fields = () raw_id_fields = ()
prepopulated_fields = {} prepopulated_fields = {}
filter_vertical = ()
filter_horizontal = ()
def __init__(self, model): def __init__(self, model):
self.model = model self.model = model
@@ -155,10 +157,8 @@ class ModelAdmin(object):
js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js'])
if self.js: if self.js:
js.extend(self.js) js.extend(self.js)
for f in self.opts.many_to_many: if self.filter_vertical or self.filter_horizontal:
if f.rel.filter_interface: js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
break
for fs in fieldsets: for fs in fieldsets:
if 'collapse' in fs.classes: if 'collapse' in fs.classes:
js.append('js/admin/CollapsedFieldsets.js') js.append('js/admin/CollapsedFieldsets.js')
@@ -205,9 +205,9 @@ class ModelAdmin(object):
If kwargs are given, they're passed to the form Field's constructor. If kwargs are given, they're passed to the form Field's constructor.
""" """
# For filter_interface ManyToManyFields, use a special Widget. # For ManyToManyFields with a filter interface, use a special Widget.
if isinstance(db_field, models.ManyToManyField) and db_field.rel.filter_interface: if isinstance(db_field, models.ManyToManyField) and db_field.name in (self.filter_vertical + self.filter_horizontal):
kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, db_field.rel.filter_interface-1) kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical))
return db_field.formfield(**kwargs) return db_field.formfield(**kwargs)
# For DateTimeFields, use a special field and widget. # For DateTimeFields, use a special field and widget.

View File

@@ -55,13 +55,14 @@ class Group(models.Model):
Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages. Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages.
""" """
name = models.CharField(_('name'), maxlength=80, unique=True) name = models.CharField(_('name'), maxlength=80, unique=True)
permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL) permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True)
class Meta: class Meta:
verbose_name = _('group') verbose_name = _('group')
verbose_name_plural = _('groups') verbose_name_plural = _('groups')
ordering = ('name',) ordering = ('name',)
class Admin: class Admin:
search_fields = ('name',) search_fields = ('name',)
filter_horizontal = ('permissions',)
def __str__(self): def __str__(self):
return self.name return self.name
@@ -99,7 +100,7 @@ class User(models.Model):
date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate()) date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.")) help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL) user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True)
objects = UserManager() objects = UserManager()
class Meta: class Meta:
verbose_name = _('user') verbose_name = _('user')
@@ -116,6 +117,7 @@ class User(models.Model):
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff') list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser') list_filter = ('is_staff', 'is_superuser')
search_fields = ('username', 'first_name', 'last_name', 'email') search_fields = ('username', 'first_name', 'last_name', 'email')
filter_horizontal = ('user_permissions',)
def __str__(self): def __str__(self):
return self.username return self.username

View File

@@ -14,7 +14,6 @@ import datetime, os, time
class NOT_PROVIDED: class NOT_PROVIDED:
pass pass
# Values for filter_interface.
HORIZONTAL, VERTICAL = 1, 2 HORIZONTAL, VERTICAL = 1, 2
# The values to use for "blank" in SelectFields. Will be appended to the start of most "choices" lists. # The values to use for "blank" in SelectFields. Will be appended to the start of most "choices" lists.

View File

@@ -249,7 +249,6 @@ class GenericRel(ManyToManyRel):
self.to = to self.to = to
self.num_in_admin = 0 self.num_in_admin = 0
self.related_name = related_name self.related_name = related_name
self.filter_interface = None
self.limit_choices_to = limit_choices_to or {} self.limit_choices_to = limit_choices_to or {}
self.edit_inline = False self.edit_inline = False
self.symmetrical = symmetrical self.symmetrical = symmetrical

View File

@@ -616,7 +616,6 @@ class ManyToManyField(RelatedField, Field):
kwargs['rel'] = ManyToManyRel(to, kwargs['rel'] = ManyToManyRel(to,
num_in_admin=kwargs.pop('num_in_admin', 0), num_in_admin=kwargs.pop('num_in_admin', 0),
related_name=kwargs.pop('related_name', None), related_name=kwargs.pop('related_name', None),
filter_interface=kwargs.pop('filter_interface', None),
limit_choices_to=kwargs.pop('limit_choices_to', None), limit_choices_to=kwargs.pop('limit_choices_to', None),
symmetrical=kwargs.pop('symmetrical', True)) symmetrical=kwargs.pop('symmetrical', True))
self.db_table = kwargs.pop('db_table', None) self.db_table = kwargs.pop('db_table', None)
@@ -757,11 +756,10 @@ class OneToOneRel(ManyToOneRel):
class ManyToManyRel(object): class ManyToManyRel(object):
def __init__(self, to, num_in_admin=0, related_name=None, def __init__(self, to, num_in_admin=0, related_name=None,
filter_interface=None, limit_choices_to=None, symmetrical=True): limit_choices_to=None, symmetrical=True):
self.to = to self.to = to
self.num_in_admin = num_in_admin self.num_in_admin = num_in_admin
self.related_name = related_name self.related_name = related_name
self.filter_interface = filter_interface
if limit_choices_to is None: if limit_choices_to is None:
limit_choices_to = {} limit_choices_to = {}
self.limit_choices_to = limit_choices_to self.limit_choices_to = limit_choices_to