From d79b9fec9c67c83f9c334fb2c13c578fb2e2aca8 Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 5 Nov 2014 16:50:10 +0000 Subject: [PATCH] Fixed issues with __unicode__() becoming __str__() in Python 3. Fixed recursion issue with VatRate --- RIGS/importer.py | 12 ++++++------ RIGS/models.py | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/RIGS/importer.py b/RIGS/importer.py index 6c72c807..eb58acb2 100644 --- a/RIGS/importer.py +++ b/RIGS/importer.py @@ -43,11 +43,11 @@ def import_people(): person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, address=row[4], notes=notes) if created: - print("Created: " + person.__unicode__()) + print("Created: " + person.__str__()) with transaction.atomic(), reversion.create_revision(): person.save() else: - print("Found: " + person.__unicode__()) + print("Found: " + person.__str__()) def import_organisations(): @@ -65,11 +65,11 @@ def import_organisations(): address=row[3], union_account=row[4], notes=notes) if created: - print("Created: " + object.__unicode__()) + print("Created: " + object.__str__()) with transaction.atomic(), reversion.create_revision(): object.save() else: - print("Found: " + object.__unicode__()) + print("Found: " + object.__str__()) def import_vat_rates(): @@ -83,11 +83,11 @@ def import_vat_rates(): object, created = models.VatRate.objects.get_or_create(pk=row[0], start_at=start_at, comment=row[3], rate=row[4]) if created: - print("Created: " + object.__unicode__()) + print("Created: " + object.__str__()) with transaction.atomic(), reversion.create_revision(): object.save() else: - print("Found: " + object.__unicode__()) + print("Found: " + object.__str__()) def main(): diff --git a/RIGS/models.py b/RIGS/models.py index 09b60177..3961798b 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -38,7 +38,7 @@ class Person(models.Model, RevisionMixin): notes = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): string = self.name if len(self.notes) > 0: string += "*" @@ -55,7 +55,7 @@ class Organisation(models.Model, RevisionMixin): notes = models.TextField(blank=True, null=True) union_account = models.BooleanField(default=False) - def __unicode__(self): + def __str__(self): string = self.name if len(self.notes) > 0: string += "*" @@ -68,8 +68,9 @@ class VatRate(models.Model, RevisionMixin): rate = models.DecimalField(max_digits=6, decimal_places=6) comment = models.CharField(max_length=255) + @property def as_percent(self): - return self.rate * 100 + return (self.rate * 100) - def __unicode__(self): + def __str__(self): return self.comment + " " + str(self.start_at) + " @ " + str(self.as_percent) + "%"