diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e7c4022f6f..1087cf8795 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -523,10 +523,10 @@ Traceback (most recent call last): ValueError: The Category could not be created because the data didn't validate. Create a couple of Writers. ->>> w = Writer(name='Mike Royko') ->>> w.save() ->>> w = Writer(name='Bob Woodward') ->>> w.save() +>>> w_royko = Writer(name='Mike Royko') +>>> w_royko.save() +>>> w_woodward = Writer(name='Bob Woodward') +>>> w_woodward.save() ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any fields with the 'choices' attribute are represented by a ChoiceField. @@ -540,8 +540,8 @@ fields with the 'choices' attribute are represented by a ChoiceField. Pub date: Writer: Article: Status:
  • Writer:
  • Article:
  • Status: Hold down "Control", or "Command" on a Mac, to select more than one.
  • ->>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) +>>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': unicode(w_royko.pk), 'article': 'Hello.'}, instance=art) >>> f.errors {} >>> f.is_valid() @@ -658,8 +658,8 @@ Add some categories and test the many-to-many form output.
  • Pub date:
  • Writer:
  • Article:
  • Status:
  • Writer:
  • Article:
  • Status: 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) +... 'writer': unicode(w_royko.pk), 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) >>> new_art = f.save() >>> new_art.id 1 @@ -709,7 +709,7 @@ Initial values can be provided for model forms Now, submit form data with no categories. This deletes the existing categories. >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', -... 'writer': u'1', 'article': u'Hello.'}, instance=new_art) +... 'writer': unicode(w_royko.pk), 'article': u'Hello.'}, instance=new_art) >>> new_art = f.save() >>> new_art.id 1 @@ -722,7 +722,7 @@ Create a new article, with categories, via the form. ... class Meta: ... model = Article >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', -... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']}) +... 'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']}) >>> new_art = f.save() >>> new_art.id 2 @@ -735,7 +735,7 @@ Create a new article, with no categories, via the form. ... class Meta: ... model = Article >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', -... 'writer': u'1', 'article': u'Test.'}) +... 'writer': unicode(w_royko.pk), 'article': u'Test.'}) >>> new_art = f.save() >>> new_art.id 3 @@ -749,7 +749,7 @@ The m2m data won't be saved until save_m2m() is invoked on the form. ... class Meta: ... model = Article >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': 'walrus-was-paul', 'pub_date': u'1967-11-01', -... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']}) +... 'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']}) >>> new_art = f.save(commit=False) # Manually save the instance @@ -798,8 +798,8 @@ the data in the database when the form is instantiated.
  • Pub date:
  • Writer:
  • Article:
  • Status:
  • Writer:
  • Article:
  • Status: - - - - + + + +

    >>> data = { -... 'writer': u'2', +... 'writer': unicode(w_woodward.pk), ... 'age': u'65', ... } >>> form = WriterProfileForm(data) @@ -1067,10 +1067,10 @@ True >>> print form.as_p()