i'm using django 1.7 , factory_boy create models. here's code:
in models.py:
class address(models.model): first_line = models.charfield(max_length=50, blank=true) second_line = models.charfield(max_length=50, blank=true) city = models.charfield(max_length=30, blank=true) state = models.charfield(max_length=2, blank=true) zipcode = models.charfield(max_length=5, blank=true) zipcode_ext = models.charfield(max_length=4, blank=true)
the associated factory in factories.py (same directory):
class addressfactory(factory.django.djangomodelfactory): class meta: model = address first_line = "555 main st." second_line = "unit 2" city = "chicago" state = "il" zipcode = "60606" zipcode_ext = "1234"
now, given code in django shell:
>>> models import address >>> django.forms.models import modelform_factory >>> addressform = modelform_factory(address) >>> factories import addressfactory >>> = addressfactory.create() >>> af = addressform(instance = a) >>> af.is_valid() false
for reason, call is_valid seems return false, , can't figure out why. there don't seem errors on form, , clean(), clean_fields(), , validate_unique() not seem raise errors on instance.
why is_valid return false?
this has nothing factory_boy. forms invalid if don't have data, yours doesn't. instance
parameter used populate form's initial data display, , determine object id updating, isn't used set data on post.
i'm not quite sure want form there, you'd need convert post dictionary , pass form's data
parameter valid.