From a3674811852ff784a98f9a3e0ffeaaf355a92761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Gu=C3=A9rin?= Date: Thu, 23 Mar 2017 17:01:14 +0100 Subject: [PATCH] Define __unicode__ and __str__ on models We use the `@python_2_unicode_compatible` python decorator to give our models both `__str__` and `__models__` See https://docs.djangoproject.com/en/1.10/topics/python3/#str-and-unicode-methods --- formidable/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/formidable/models.py b/formidable/models.py index 8cb38fe2..a5a68175 100644 --- a/formidable/models.py +++ b/formidable/models.py @@ -4,11 +4,13 @@ from django.core.exceptions import ValidationError from django.db import models +from django.utils.encoding import python_2_unicode_compatible from formidable import constants from formidable.register import FieldSerializerRegister +@python_2_unicode_compatible class Formidable(models.Model): label = models.CharField(max_length=256) @@ -58,6 +60,7 @@ def __str__(self): return '{formidable.label}'.format(formidable=self) +@python_2_unicode_compatible class Field(models.Model): class Meta: @@ -87,6 +90,7 @@ def __str__(self): return '{field.label}'.format(field=self) +@python_2_unicode_compatible class Default(models.Model): value = models.CharField(max_length=256) @@ -96,6 +100,7 @@ def __str__(self): return '{default.value}'.format(default=self) +@python_2_unicode_compatible class Item(models.Model): field = models.ForeignKey(Field, related_name='items') value = models.CharField(max_length=256) @@ -107,6 +112,7 @@ def __str__(self): return '{item.label}: {item.value}'.format(item=self) +@python_2_unicode_compatible class Access(models.Model): class Meta: @@ -124,6 +130,7 @@ def __str__(self): access=self) +@python_2_unicode_compatible class Validation(models.Model): field = models.ForeignKey(Field, related_name='validations') value = models.CharField(max_length=256) @@ -135,6 +142,7 @@ def __str__(self): validation=self) +@python_2_unicode_compatible class Preset(models.Model): form = models.ForeignKey(Formidable, related_name='presets') slug = models.CharField(max_length=128) @@ -144,6 +152,7 @@ def __str__(self): return '{preset.slug}'.format(preset=self) +@python_2_unicode_compatible class PresetArg(models.Model): preset = models.ForeignKey(Preset, related_name='arguments') slug = models.CharField(max_length=128)