Skip to content

Instantly share code, notes, and snippets.

@bogsio
Created July 23, 2014 16:27
Show Gist options
  • Save bogsio/8dd168b653df7f11159b to your computer and use it in GitHub Desktop.
Save bogsio/8dd168b653df7f11159b to your computer and use it in GitHub Desktop.
TPT2 - Adding unicode to models
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