Skip to content

Commit

Permalink
Merge pull request #169 from tam0407/feature/fix-python2-unicode-comp…
Browse files Browse the repository at this point in the history
…atible-with-python3

Fix example app: python2 unicode compatible when using python3
  • Loading branch information
mlavin committed Jun 14, 2016
2 parents d8514a9 + 5649c7b commit f722bd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions example/core/models.py
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
2 changes: 1 addition & 1 deletion example/core/templates/formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endblock %}

{% block extra-js %}
<script type="text/javascript" src="http://django-dynamic-formset.googlecode.com/svn/trunk/src/jquery.formset.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.formset/1.2.2/jquery.formset.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#id_farm_table tbody tr').formset({
Expand Down

0 comments on commit f722bd2

Please sign in to comment.