"First, why does uf.is_valid() return"

because you called "uf.is_valid" (note the lack of parenthesis), that's
just a reference to the method and does not call it.

"Second, why does uf.save() return that stacktrace the first time I call
it, but the second time I call it, the object saves? "

As far as I know ModelForm subclasses take a dictionary as a first
parameter, not the object itself, you would need to do something like this:

uf = UsersForm(instance=u)

I don't know why it works the second time (if it does indeed work)


On Sun, Jan 3, 2016 at 1:13 AM, Sergiy Khohlov <[email protected]> wrote:

> Sorry I missed. You have valid unknown at the start. Why are you not used
> django user model and author? Study purpose ,?
> 3 січ. 2016 05:53 "Michael Molloy" <[email protected]> пише:
>
> I'm not sure what could be wrong with the database settings. If I just
>> create an instance of the model and save it, it saves to the database:
>>
>>
>> <https://lh3.googleusercontent.com/-jyOjeZShpXU/VoibBXC7gPI/AAAAAAAAAFU/WeJ9TBxQemQ/s1600/Screen%2BShot%2B2016-01-02%2Bat%2B9.52.18%2BPM.png>
>>
>> >>> u.email = '[email protected]'
>>
>> >>> u.save()
>>
>>
>>
>> <https://lh3.googleusercontent.com/-jyOjeZShpXU/VoibBXC7gPI/AAAAAAAAAFU/WeJ9TBxQemQ/s1600/Screen%2BShot%2B2016-01-02%2Bat%2B9.52.18%2BPM.png>
>>
>> --M
>>
>> On Saturday, January 2, 2016 at 9:48:39 PM UTC-6, Sergiy Khohlov wrote:
>>>
>>> Is_valid is working. You have
>>> problem with save. Check database setting.
>>>
>>> 3 січ. 2016 04:18 "Michael Molloy" <[email protected]> пише:
>>> >ve
>>> > This is running in Openshift with Python 3.3 and Django 1.8.4
>>> >
>>> > Here's my model:
>>> >
>>> > class Users(models.Model):
>>> >     first_nm = models.CharField('First Name', max_length=100)
>>> >     last_nm = models.CharField('Last Name', max_length=100)
>>> >     email = models.CharField('Email Address', max_length=200,
>>> unique=True)
>>> >
>>> >
>>> > Here's my form:
>>> >
>>> > class UsersForm(forms.ModelForm):
>>> >     class Meta:
>>> >         model = Users
>>> >         fields = ['first_nm', 'last_nm', 'email']
>>> >
>>> >
>>> >
>>> > When I run the shell inside Openshift, this is what happens:
>>> >
>>> > Python 3.3.2 (default, Mar 20 2014, 20:25:51)
>>> >
>>> > [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
>>> >
>>> > Type "help", "copyright", "credits" or "license" for more information.
>>> >
>>> > (InteractiveConsole)
>>> >
>>> >
>>> > >>> from django.conf import settings
>>> >
>>> > >>> from package.forms import UsersForm
>>> >
>>> > >>> from package.models import Users
>>> >
>>> >
>>> > >>> u = Users()
>>> >
>>> > >>> u.first_nm = 'First'
>>> >
>>> > >>> u.last_nm = 'Last'
>>> >
>>> > >>> u.email = '[email protected]'
>>> >
>>> > >>> uf = UsersForm(u)
>>> >
>>> > >>> uf.is_bound
>>> >
>>> > True
>>> >
>>> > >>> uf.is_valid
>>> >
>>> > <bound method UsersForm.is_valid of <UsersForm bound=True,
>>> valid=Unknown, fields=(first_nm;last_nm;email)>>
>>> >
>>> >
>>> > >>> uf.save()
>>> >
>>> >
>>> > Traceback (most recent call last):
>>> >
>>> >   File "<console>", line 1, in <module>
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/models.py",
>>> line 463, in save
>>> >
>>> >     construct=False)
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/models.py",
>>> line 84, in save_instance
>>> >
>>> >     if form.errors:
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/forms.py",
>>> line 176, in errors
>>> >
>>> >     self.full_clean()
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/forms.py",
>>> line 392, in full_clean
>>> >
>>> >     self._clean_fields()
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/forms.py",
>>> line 401, in _clean_fields
>>> >
>>> >     value = field.widget.value_from_datadict(self.data, self.files,
>>> self.add_prefix(name))
>>> >
>>> >   File
>>> "/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib/python3.3/site-packages/Django-1.8.4-py3.3.egg/django/forms/widgets.py",
>>> line 223, in value_from_datadict
>>> >
>>> >     return data.get(name, None)
>>> >
>>> > AttributeError: 'Users' object has no attribute 'get'
>>> >
>>> >
>>> > >>> uf.save()
>>> >
>>> > <Users: Users object>
>>> >
>>> >
>>> > First, why does uf.is_valid() return
>>> >
>>> >
>>> > <bound method UsersForm.is_valid of <UsersForm bound=True,
>>> valid=Unknown, fields=(first_nm;last_nm;email)>>
>>> >
>>> >
>>> > the first time I call it, but on subsequent calls, uf.is_valid()
>>> returns True?
>>> >
>>> >
>>> > Second, why does uf.save() return that stacktrace the first time I
>>> call it, but the second time I call it, the object saves?
>>> >
>>> >
>>> > Third, even though the Users object saves, the only value in the
>>> database for that row is the primary key. Neither the names nor the email
>>> field is saved.
>>> >
>>> >
>>> >
>>> > I'm working through the Django Unchained book, and I'm also looking at
>>> the Django tutorial on djangoproject.com, and it looks to me like I'm
>>> doing everything that I'm supposed to, but obviously I'm missing something.
>>> >
>>> >
>>> > --Michael
>>> >
>>> >
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> > To post to this group, send email to [email protected].
>>> > Visit this group at https://groups.google.com/group/django-users.
>>> > To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/dd08dc98-e3af-49c8-b549-c5dc4e72d3d6%40googlegroups.com
>>> .
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/72973c30-8cde-497d-822e-d3b01d3bc3ab%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/72973c30-8cde-497d-822e-d3b01d3bc3ab%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADTRxJN%3D%2BPd9%2BbS_EqOe%3DdrDpO--OUq8fupp06SrRg-mV0Hi7g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADTRxJN%3D%2BPd9%2BbS_EqOe%3DdrDpO--OUq8fupp06SrRg-mV0Hi7g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2DjETVMRU%2BW55dhHKA5EQ0h2i1xNfTC_vWF3wV_ZVfog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to