Skip to content

Instantly share code, notes, and snippets.

@mineta
Created March 2, 2014 12:20
Show Gist options
  • Save mineta/9305782 to your computer and use it in GitHub Desktop.
Save mineta/9305782 to your computer and use it in GitHub Desktop.
# Based on Example in https://docs.djangoproject.com/en/1.5/topics/testing/doctests/
from django.db import models
class Animal(models.Model):
"""
An animal that makes noise
# Create an animal
>>> lion = Animal.objects.create(name="lion", sound="roar")
# Test it makes the correct noise
>>> lion.speak()
'The lion says "roar"'
"""
name = models.CharField(max_length=20)
sound = models.CharField(max_length=20)
def speak(self):
return 'The %s says "%s"' % (self.name, self.sound)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment