Thank you for your help. I apologize for the typo, but I am calling
is_valid() with the parenthesis:
>>> uf = UsersForm(u)
>>> uf.is_valid()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib64/python3.3/site-packages/django/forms/forms.py"
, line 184, in is_valid
return self.is_bound and not self.errors
File
"/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib64/python3.3/site-packages/django/forms/forms.py"
, line 176, in errors
self.full_clean()
File
"/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib64/python3.3/site-packages/django/forms/forms.py"
, line 392, in full_clean
self._clean_fields()
File
"/var/lib/openshift/5678c24389f5cff0330001cd/python/virtenv/venv/lib64/python3.3/site-packages/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/lib64/python3.3/site-packages/django/forms/widgets.py"
, line 223, in value_from_datadict
return data.get(name, None)
AttributeError: 'Users' object has no attribute 'get'
>>> uf.is_valid()
True
As for creating the form instance with the instance keyword, I tried that
first as I saw it in the materials I was reading, but it doesn't work. Note
the code below. is_bound = False if I use instance=u. If I just pass the
Users instance without the 'instance' keyword, is_bound returns True.
>>> u = Users()
>>> u.email = '[email protected]'
>>> uf = UsersForm(u)
>>> uf.is_bound
True
>>> uf = UsersForm(instance=u)
>>> uf.is_bound
False
--M
On Saturday, January 2, 2016 at 10:16:38 PM UTC-6, Vijay Khemlani wrote:
>
> "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]
> <javascript:>> 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] <javascript:>>
>> пише:
>>
>> 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] <javascript:>'
>>>
>>> >>> 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] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> 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/5ede86ea-413d-4d52-b5aa-d7f39d271a5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.