Skip to content

Instantly share code, notes, and snippets.

@bicknest
Last active May 8, 2020 00:14
Show Gist options
  • Save bicknest/9699064dc47cf6481c4c8ddbe27365a4 to your computer and use it in GitHub Desktop.
Save bicknest/9699064dc47cf6481c4c8ddbe27365a4 to your computer and use it in GitHub Desktop.
>>> from core.models import Business
>>> from core.models import Profile
>>> from core.schema import ProfileForm
>>> b = Business.objects.first()
>>> data = {"phone_number": "+15555555555"}
>>> f = ProfileForm(data=data)
>>> f.is_valid()
False
>>> f.errors
{'age': ['This field is required.'], 'business': ['This field is required.']}
>>> data = {"phone_number": "+15555555555", "business": b, "age": 25}
>>> f = ProfileForm(data=data)
>>> f.save()
<Profile: Profile object (1)>
>>> p = Profile.objects.first()
>>> form = ProfileForm(data={"business": b, "age": "blah", "phone_number": "+155555558"}, instance=p)
>>> form.is_valid()
False
>>> form.errors
{'age': ['Enter a whole number.']}
>>> form = ProfileForm(data={"business": b, "age": 24, "phone_number": "+155555558"}, instance=p)
>>> form.is_valid()
True
>>> form.save()
<Profile: Profile object (1)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment