diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-06-06 01:21:49 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2006-06-06 01:21:49 +0000 |
| commit | e976ed1f7910fad03704f88853c5c5b36cbab134 (patch) | |
| tree | c4c8d32d4298f64ad9ce8e7813084c2f45a9dc40 /tests/modeltests/str | |
| parent | 0c341d780ebcde0e81c81eda07e2db3aaa92549b (diff) | |
multi-auth: Merged to [3085]
git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@3086 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/str')
| -rw-r--r-- | tests/modeltests/str/__init__.py | 0 | ||||
| -rw-r--r-- | tests/modeltests/str/models.py | 31 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/modeltests/str/__init__.py b/tests/modeltests/str/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/modeltests/str/__init__.py diff --git a/tests/modeltests/str/models.py b/tests/modeltests/str/models.py new file mode 100644 index 0000000000..4e4228ac89 --- /dev/null +++ b/tests/modeltests/str/models.py @@ -0,0 +1,31 @@ +""" +2. Adding __str__() to models + +Although it's not a strict requirement, each model should have a ``__str__()`` +method to return a "human-readable" representation of the object. Do this not +only for your own sanity when dealing with the interactive prompt, but also +because objects' representations are used throughout Django's +automatically-generated admin. +""" + +from django.db import models + +class Article(models.Model): + headline = models.CharField(maxlength=100) + pub_date = models.DateTimeField() + + def __str__(self): + return self.headline + +API_TESTS = """ +# Create an Article. +>>> from datetime import datetime +>>> a = Article(headline='Area man programs in Python', pub_date=datetime(2005, 7, 28)) +>>> a.save() + +>>> str(a) +'Area man programs in Python' + +>>> a +<Article: Area man programs in Python> +""" |
