Loading tests/modeltests/repr/__init__.py→tests/modeltests/str/__init__.py +0 −0 File moved. tests/modeltests/repr/models.py→tests/modeltests/str/models.py +5 −5 Original line number Diff line number Diff line """ 2. Adding __repr__() to models 2. Adding __str__() to models Although it's not a strict requirement, each model should have a ``__repr__()`` 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 Loading @@ -14,7 +14,7 @@ class Article(models.Model): headline = models.CharField(maxlength=100) pub_date = models.DateTimeField() def __repr__(self): def __str__(self): return self.headline API_TESTS = """ Loading @@ -23,9 +23,9 @@ API_TESTS = """ >>> a = Article(headline='Area man programs in Python', pub_date=datetime(2005, 7, 28)) >>> a.save() >>> repr(a) >>> str(a) 'Area man programs in Python' >>> a Area man programs in Python <Article: Area man programs in Python> """ Loading
tests/modeltests/repr/models.py→tests/modeltests/str/models.py +5 −5 Original line number Diff line number Diff line """ 2. Adding __repr__() to models 2. Adding __str__() to models Although it's not a strict requirement, each model should have a ``__repr__()`` 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 Loading @@ -14,7 +14,7 @@ class Article(models.Model): headline = models.CharField(maxlength=100) pub_date = models.DateTimeField() def __repr__(self): def __str__(self): return self.headline API_TESTS = """ Loading @@ -23,9 +23,9 @@ API_TESTS = """ >>> a = Article(headline='Area man programs in Python', pub_date=datetime(2005, 7, 28)) >>> a.save() >>> repr(a) >>> str(a) 'Area man programs in Python' >>> a Area man programs in Python <Article: Area man programs in Python> """