From d22290b2ce00909c2f92b6dacadfbfb0deeefd7f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 2 May 2009 07:16:30 +0000 Subject: [1.0.X] Fixed #10349 -- Modified ManyToManyFields to allow initial form values to be callables. Thanks to fas for the report and patch. Merge of r10652 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10653 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/modeltests/model_forms/models.py') diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index ec9e75a705..f90568c5d0 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -569,6 +569,30 @@ Add some categories and test the many-to-many form output. Hold down "Control", or "Command" on a Mac, to select more than one. +Initial values can be provided for model forms +>>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']}) +>>> print f.as_ul() +
  • Headline:
  • +
  • Slug:
  • +
  • Pub date:
  • +
  • Writer:
  • +
  • Article:
  • +
  • Status:
  • +
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • + >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) >>> new_art = f.save() -- cgit v1.3