summaryrefslogtreecommitdiff
path: root/django/db/models/fields
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-27 05:23:21 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-27 05:23:21 +0000
commit6a75c8a52ef01c680677c13cefb08a9ccbe38562 (patch)
tree1c5ec29689a99021546d39a8c32945c72349b22e /django/db/models/fields
parentd853278253b5efa60a691ae9b83fb6352d2a91f0 (diff)
newforms: Implemented formfield() for database ForeignKey class and added unit tests
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4247 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/fields')
-rw-r--r--django/db/models/fields/related.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ce33968974..eb388fcb6d 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -361,7 +361,7 @@ def create_many_related_manager(superclass):
old_ids = set([obj._get_pk_val() for obj in objs])
cursor = connection.cursor()
cursor.execute("DELETE FROM %s WHERE %s = %%s AND %s IN (%s)" % \
- (self.join_table, source_col_name,
+ (self.join_table, source_col_name,
target_col_name, ",".join(['%s'] * len(old_ids))),
[self._pk_val] + list(old_ids))
transaction.commit_unless_managed()
@@ -548,6 +548,9 @@ class ForeignKey(RelatedField, Field):
def contribute_to_related_class(self, cls, related):
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
+ def formfield(self):
+ return forms.ChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name))
+
class OneToOneField(RelatedField, IntegerField):
def __init__(self, to, to_field=None, **kwargs):
try: