From 93d83df61195ea598bc0a2a5cdce1df8e88fcb6d Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Fri, 15 Dec 2006 18:32:47 +0000 Subject: boulder-oracle-sprint: Merged to trunk [4210]. git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4212 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/models.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/modeltests/model_forms/models.py (limited to 'tests/modeltests/model_forms/models.py') diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py new file mode 100644 index 0000000000..b51b4e1a8b --- /dev/null +++ b/tests/modeltests/model_forms/models.py @@ -0,0 +1,44 @@ +""" +34. Generating HTML forms from models + +Django provides shortcuts for creating Form objects from a model class. +""" + +from django.db import models + +class Category(models.Model): + name = models.CharField(maxlength=20) + url = models.CharField('The URL', maxlength=20) + + def __str__(self): + return self.name + +class Article(models.Model): + headline = models.CharField(maxlength=50) + pub_date = models.DateTimeField() + categories = models.ManyToManyField(Category) + + def __str__(self): + return self.headline + +__test__ = {'API_TESTS': """ +>>> from django.newforms import form_for_model +>>> CategoryForm = form_for_model(Category) +>>> f = CategoryForm() +>>> print f + + + +>>> print f.as_ul() +
  • +
  • +
  • +>>> print f['name'] + + +>>> f = CategoryForm(auto_id=False) +>>> print f.as_ul() +
  • ID:
  • +
  • Name:
  • +
  • The URL:
  • +"""} -- cgit v1.3