summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-28 02:27:14 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-28 02:27:14 +0000
commit34dce706ee9ac30d950d95e1647aadbed2a70921 (patch)
tree6d5d116cfc82f911a15c98ab0e70455b373cd841
parentf974b1bb5af7fe21de71f223a43ee1c0cdcf8f8f (diff)
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
-rw-r--r--django/db/models/fields/__init__.py4
-rw-r--r--django/db/models/fields/related.py4
2 files changed, 8 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index ba4f8894e8..ddf3003d55 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -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):
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 8cc26c9ee4..433b5bde13 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -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)