From 364df9ec72cefe18225ae0fea7ae591c57bd3f81 Mon Sep 17 00:00:00 2001 From: Travis Dart Date: Thu, 1 Aug 2019 03:28:43 +0000 Subject: [PATCH] Updates and python3 changes. --- formstorm/FormTest.py | 14 ++++++++------ formstorm/__init__.py | 4 ++-- tests/fstestapp/models.py | 2 +- tests/fstestapp/test.py | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/formstorm/FormTest.py b/formstorm/FormTest.py index 3cd73d4..d29b2ef 100644 --- a/formstorm/FormTest.py +++ b/formstorm/FormTest.py @@ -1,7 +1,7 @@ -from FormElement import FormElement +from .FormElement import FormElement from django.db import transaction from django.forms import ModelForm -from iterhelpers import dict_combo +from .iterhelpers import dict_combo class FormTest(object): @@ -13,7 +13,6 @@ def is_good(self): def submit_form(self, form_values): self.bound_form = self.form(form_values) if self._is_modelform and self.bound_form.is_valid(): - print "Save!" self.bound_form.save() def _build_elements(self): @@ -22,10 +21,13 @@ def _build_elements(self): # Filter out this class's FormElement properties if type(getattr(self, e)) is FormElement: # If this field is a fk/m2m, get the model that it points to. - try: - ref_model = self.form._meta.model._meta.get_field(e).rel.to + try: # Python 3 + ref_model = self.form._meta.model._meta.get_field(e).remote_field.model except AttributeError: - ref_model = None + try: + ref_model = self.form._meta.model._meta.get_field(e).rel.to + except AttributeError: + ref_model = None self.elements[e] = getattr(self, e).build_iterator( is_e2e=self.is_e2e, diff --git a/formstorm/__init__.py b/formstorm/__init__.py index a05cbc2..f00761f 100644 --- a/formstorm/__init__.py +++ b/formstorm/__init__.py @@ -1,5 +1,5 @@ -from FormTest import FormTest # noqa: F401 -from FormElement import FormElement # noqa: F401 +from .FormTest import FormTest # noqa: F401 +from .FormElement import FormElement # noqa: F401 __version__ = '1.0.0beta1' name = "formstorm" diff --git a/tests/fstestapp/models.py b/tests/fstestapp/models.py index 97fc06d..b25cb0d 100644 --- a/tests/fstestapp/models.py +++ b/tests/fstestapp/models.py @@ -18,7 +18,7 @@ def __unicode__(self): class Book(models.Model): title = models.CharField(max_length=100, unique=True) subtitle = models.CharField(max_length=100, blank=True, null=True) - author = models.ForeignKey(Author) + author = models.ForeignKey(Author, on_delete=models.CASCADE) is_fiction = models.BooleanField(default=False) pages = models.IntegerField(default=False) genre = models.ManyToManyField(Genre) diff --git a/tests/fstestapp/test.py b/tests/fstestapp/test.py index 9c6ceae..8fb7517 100644 --- a/tests/fstestapp/test.py +++ b/tests/fstestapp/test.py @@ -1,8 +1,8 @@ from formstorm import FormTest, FormElement from formstorm.iterhelpers import every_combo -from forms import BookForm +from .forms import BookForm from django.test import TestCase -from models import Author, Genre +from .models import Author, Genre from django.db.models import Q