Added value_from_object method to db Field class

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4252 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-12-28 02:27:14 +00:00
parent f974b1bb5a
commit 34dce706ee
2 changed files with 8 additions and 0 deletions

View File

@ -339,6 +339,10 @@ class Field(object):
# TODO: This is just a temporary default during development.
return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)
def value_from_object(self, obj):
"Returns the value of this field in the given model instance."
return getattr(obj, self.attname)
class AutoField(Field):
empty_strings_allowed = False
def __init__(self, *args, **kwargs):

View File

@ -721,6 +721,10 @@ class ManyToManyField(RelatedField, Field):
def set_attributes_from_rel(self):
pass
def value_from_object(self, obj):
"Returns the value of this field in the given model instance."
return getattr(obj, self.attname).all()
def formfield(self, initial=None):
return forms.MultipleChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial)