Created
July 23, 2014 16:27
-
-
Save bogsio/8dd168b653df7f11159b to your computer and use it in GitHub Desktop.
TPT2 - Adding unicode to models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| from django.contrib.auth.models import User | |
| class TodoList(models.Model): | |
| name = models.CharField('List Title', max_length=200) | |
| author = models.ForeignKey(User, related_name='todo_lists') | |
| def __unicode__(self): | |
| return '"' + self.name + '" by ' + unicode(self.author) | |
| class TodoItem(models.Model): | |
| text = models.TextField('Item Text') | |
| todo_list = models.ForeignKey(TodoList, related_name='items') | |
| 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