mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +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:
parent
1d421ab9c4
commit
907feaacc7
@ -332,8 +332,8 @@ class Field(object):
|
|||||||
|
|
||||||
def flatten_data(self, follow, obj = None):
|
def flatten_data(self, follow, obj = None):
|
||||||
"""
|
"""
|
||||||
Returns a dictionary mapping the field's manipulator field names to its
|
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
|
"flattened" string values for the admin view. Obj is the instance to extract the
|
||||||
values from.
|
values from.
|
||||||
"""
|
"""
|
||||||
return { self.attname : self._get_val_from_obj(obj)}
|
return { self.attname : self._get_val_from_obj(obj)}
|
||||||
@ -412,7 +412,7 @@ class DateField(Field):
|
|||||||
return [formfields.DateField]
|
return [formfields.DateField]
|
||||||
|
|
||||||
def flatten_data(self, follow, obj = None):
|
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 '')}
|
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
|
||||||
|
|
||||||
class DateTimeField(DateField):
|
class DateTimeField(DateField):
|
||||||
@ -446,9 +446,9 @@ class DateTimeField(DateField):
|
|||||||
|
|
||||||
def flatten_data(self,follow, obj = None):
|
def flatten_data(self,follow, obj = None):
|
||||||
val = self._get_val_from_obj(obj)
|
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 ''),
|
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):
|
class EmailField(Field):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
@ -778,9 +778,10 @@ class ManyToManyField(Field):
|
|||||||
else:
|
else:
|
||||||
# In required many-to-many fields with only one available choice,
|
# In required many-to-many fields with only one available choice,
|
||||||
# select that 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:
|
if not self.blank and not self.rel.edit_inline and not self.rel.raw_id_admin:
|
||||||
choice_list = self.get_choices_default()
|
choices_list = self.get_choices_default()
|
||||||
if len(choice_list) == 1:
|
if len(choices_list) == 1:
|
||||||
|
print self.name, choices_list[0][0]
|
||||||
new_data[self.name] = [choices_list[0][0]]
|
new_data[self.name] = [choices_list[0][0]]
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user