Skip to content

Instantly share code, notes, and snippets.

@bogsio
Created July 24, 2014 10:35
Show Gist options
  • Save bogsio/74e1a8ead551d9ce9e5a to your computer and use it in GitHub Desktop.
Save bogsio/74e1a8ead551d9ce9e5a to your computer and use it in GitHub Desktop.
TPT3 - Adding to_dict
class TodoItem(models.Model):
text = models.TextField('Item Text')
todo_list = models.ForeignKey(TodoList, related_name='items')
def to_dict(self):
return {'text': self.text, 'id': self.pk}
def __unicode__(self):
return self.text[:50] + ' ' + unicode(self.todo_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment