Skip to content

Commit

Permalink
Updates and python3 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisDart committed Aug 1, 2019
1 parent 1b8081d commit 364df9e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions formstorm/FormTest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions formstorm/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion tests/fstestapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/fstestapp/test.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down

0 comments on commit 364df9e

Please sign in to comment.