Create a gist now

Instantly share code, notes, and snippets.

@ColonelThirtyTwo / Secret
Last active Aug 29, 2015

What would you like to do?
Django InlineFormset ValueError
from django.db import models
class Container(models.Model):
class Item(models.Model):
container = models.ForeignKey(Container)
data = models.CharField(max_length=123)
from django.test import TestCase
from django.forms.models import inlineformset_factory, BaseInlineFormSet
from test_app.models import Container, Item
TestFormSet = inlineformset_factory(Container, Item, extra=0)
class MyTestCase(TestCase):
def setUp(self):
self.container = Container.objects.create()
self.existingItem = Item.objects.create(container=self.container, data="asdf")
self.test_data = {
"item_set-TOTAL_FORMS": "2",
"item_set-MAX_NUM_FORMS": "1000",
"item_set-INITIAL_FORMS": "1",
"item_set-0-id": "", # Not valid
"item_set-0-data": "foo",
"item_set-1-id": str(,
"item_set-1-data": str(,
def test_django_formset_int_error(self):
formset = TestFormSet(self.test_data, instance=self.container)
except ValueError:"Formset.is_valid() raised unexpected exception.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment