mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
newforms-admin: Applied the same _has_changed treatment to the ManyToManyRawIdWidget from [7515] since it acts similar with the underlying data.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7516 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6b6778ac46
commit
be31882eee
@ -7,6 +7,7 @@ from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.text import capfirst, truncate_words
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.conf import settings
|
||||
|
||||
class FilteredSelectMultiple(forms.SelectMultiple):
|
||||
@ -135,6 +136,18 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
||||
if value:
|
||||
return [value]
|
||||
return None
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
if initial is None:
|
||||
initial = []
|
||||
if data is None:
|
||||
data = []
|
||||
if len(initial) != len(data):
|
||||
return True
|
||||
for pk1, pk2 in zip(initial, data):
|
||||
if force_unicode(pk1) != force_unicode(pk2):
|
||||
return True
|
||||
return False
|
||||
|
||||
class RelatedFieldWidgetWrapper(object):
|
||||
"""
|
||||
|
@ -66,6 +66,18 @@ Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br />Change: <i
|
||||
>>> w = ManyToManyRawIdWidget(rel)
|
||||
>>> print conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={}))
|
||||
<input type="text" name="test" value="1,2" class="vManyToManyRawIdAdminField" /><a href="../../../admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>
|
||||
>>> w._has_changed(None, None)
|
||||
False
|
||||
>>> w._has_changed([], None)
|
||||
False
|
||||
>>> w._has_changed(None, [u'1'])
|
||||
True
|
||||
>>> w._has_changed([1, 2], [u'1', u'2'])
|
||||
False
|
||||
>>> w._has_changed([1, 2], [u'1'])
|
||||
True
|
||||
>>> w._has_changed([1, 2], [u'1', u'3'])
|
||||
True
|
||||
|
||||
""" % {
|
||||
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
|
||||
|
Loading…
x
Reference in New Issue
Block a user