Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class Address(models.Model):
  2. first_line = models.CharField(max_length=50, blank=True)
  3. second_line = models.CharField(max_length=50, blank=True)
  4. city = models.CharField(max_length=30, blank=True)
  5. state = models.CharField(max_length=2, blank=True)
  6. zipcode = models.CharField(max_length=5, blank=True)
  7. zipcode_ext = models.CharField(max_length=4, blank=True)
  8.  
  9. class AddressFactory(factory.django.DjangoModelFactory):
  10. class Meta:
  11. model = Address
  12.  
  13. first_line = "555 Main St."
  14. second_line = "Unit 2"
  15. city = "Chicago"
  16. state = "IL"
  17. zipcode = "60606"
  18. zipcode_ext = "1234"
  19.  
  20. >>> from models import Address
  21. >>> from django.forms.models import modelform_factory
  22. >>> AddressForm = modelform_factory(Address)
  23. >>> from factories import AddressFactory
  24. >>> a = AddressFactory.create()
  25. >>> af = AddressForm(instance = a)
  26. >>> af.is_valid()
  27. False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement