1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

new_admin: fixes a problem with init on ManyToMany fields with only one possible selection

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1222 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Georg Bauer 2005-11-14 00:04:29 +00:00
parent 1d421ab9c4
commit 907feaacc7

View File

@ -332,8 +332,8 @@ class Field(object):
def flatten_data(self, follow, obj = None):
"""
Returns a dictionary mapping the field's manipulator field names to its
"flattened" string values for the admin view. Obj is the instance to extract the
Returns a dictionary mapping the field's manipulator field names to its
"flattened" string values for the admin view. Obj is the instance to extract the
values from.
"""
return { self.attname : self._get_val_from_obj(obj)}
@ -412,7 +412,7 @@ class DateField(Field):
return [formfields.DateField]
def flatten_data(self, follow, obj = None):
val = self._get_val_from_obj(obj)
val = self._get_val_from_obj(obj)
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
class DateTimeField(DateField):
@ -446,9 +446,9 @@ class DateTimeField(DateField):
def flatten_data(self,follow, obj = None):
val = self._get_val_from_obj(obj)
date_field, time_field = self.get_manipulator_field_names('')
date_field, time_field = self.get_manipulator_field_names('')
return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''),
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
class EmailField(Field):
def get_manipulator_field_objs(self):
@ -778,9 +778,10 @@ class ManyToManyField(Field):
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 and self.choices:
choice_list = self.get_choices_default()
if len(choice_list) == 1:
if not self.blank and not self.rel.edit_inline and not self.rel.raw_id_admin:
choices_list = self.get_choices_default()
if len(choices_list) == 1:
print self.name, choices_list[0][0]
new_data[self.name] = [choices_list[0][0]]
return new_data