-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from tam0407/feature/fix-python2-unicode-comp…
…atible-with-python3 Fix example app: python2 unicode compatible when using python3
- Loading branch information
Showing
2 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
from __future__ import unicode_literals | ||
|
||
from six import python_2_unicode_compatible | ||
|
||
try: | ||
from localflavor.us.models import USStateField | ||
except ImportError: | ||
from django.contrib.localflavor.us.models import USStateField | ||
from django.db import models | ||
|
||
|
||
@python_2_unicode_compatible | ||
class Fruit(models.Model): | ||
name = models.CharField(max_length=200) | ||
|
||
def __unicode__(self): | ||
def __str__(self): | ||
return self.name | ||
|
||
|
||
@python_2_unicode_compatible | ||
class Farm(models.Model): | ||
name = models.CharField(max_length=200) | ||
owner = models.ForeignKey('auth.User', related_name='farms') | ||
fruit = models.ManyToManyField(Fruit) | ||
|
||
def __unicode__(self): | ||
def __str__(self): | ||
return "%s's Farm: %s" % (self.owner.username, self.name) | ||
|
||
|
||
@python_2_unicode_compatible | ||
class City(models.Model): | ||
name = models.CharField(max_length=200) | ||
state = USStateField() | ||
|
||
def __unicode__(self): | ||
def __str__(self): | ||
return self.name |
This file contains 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