1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +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
raw_id_fields = ()
prepopulated_fields = {}
filter_vertical = ()
filter_horizontal = ()
def __init__(self, model):
self.model = model
@@ -155,10 +157,8 @@ class ModelAdmin(object):
js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js'])
if self.js:
js.extend(self.js)
for f in self.opts.many_to_many:
if f.rel.filter_interface:
if self.filter_vertical or self.filter_horizontal:
js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
break
for fs in fieldsets:
if 'collapse' in fs.classes:
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.
"""
# For filter_interface ManyToManyFields, use a special Widget.
if isinstance(db_field, models.ManyToManyField) and db_field.rel.filter_interface:
kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, db_field.rel.filter_interface-1)
# For ManyToManyFields with a filter interface, use a special Widget.
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.name in self.filter_vertical))
return db_field.formfield(**kwargs)
# 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.
"""
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:
verbose_name = _('group')
verbose_name_plural = _('groups')
ordering = ('name',)
class Admin:
search_fields = ('name',)
filter_horizontal = ('permissions',)
def __str__(self):
return self.name
@@ -99,7 +100,7 @@ class User(models.Model):
date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
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."))
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()
class Meta:
verbose_name = _('user')
@@ -116,6 +117,7 @@ class User(models.Model):
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser')
search_fields = ('username', 'first_name', 'last_name', 'email')
filter_horizontal = ('user_permissions',)
def __str__(self):
return self.username

View File

@@ -14,7 +14,6 @@ import datetime, os, time
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.

View File

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

View File

@@ -616,7 +616,6 @@ 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),
symmetrical=kwargs.pop('symmetrical', True))
self.db_table = kwargs.pop('db_table', None)
@@ -757,11 +756,10 @@ class OneToOneRel(ManyToOneRel):
class ManyToManyRel(object):
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.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