need to find out if someone is an orphan when I have mother_alive and father_alive fields in the database

20 views
Skip to first unread message

eil...@themaii.org

unread,
Jan 29, 2018, 3:03:01 PM1/29/18
to Django users
Hi,
I need to find out if someone is an orphan when I have mother_alive and father_alive fields in the database. Stepfathers, and stepmothers etc aren't counted when determining if someone is an orphan, only their birth mother, and birth father.
I tried 
  if form['orphaned'].data == True:
             q = context['child_filter'].filter(Q(request.POST.get('mother_alive') == 0 and request.POST.get('father_alive') == 0))

but I got an error on it.

does anyone know what I did wrong?

-Eileen



Etienne Robillard

unread,
Jan 29, 2018, 3:44:13 PM1/29/18
to eil...@themaii.org, django...@googlegroups.com

Hi Eileen,

What is the error message?

By the way, one way to improve your code readability would be to use form.is_valid() :

For instance:

new_data = form.is_valid()

Hope this helps,

Etienne

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/f49ad522-cbcc-4aa9-8126-636231b36bfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Etienne Robillard
tka...@yandex.com
https://www.isotopesoftware.ca/

Jani Tiainen

unread,
Jan 29, 2018, 5:07:32 PM1/29/18
to django...@googlegroups.com
Hi.

Your code is incomplete and actual error (whole traceback is missing)

Also you're trying to mix usage of form and reading post data directly. You should only use form to deal with user input. See https://docs.djangoproject.com/en/2.0/topics/forms/  for more information.

Finally with Q queries you don't use and-operator. See details at 
https://docs.djangoproject.com/en/2.0/topics/db/queries/#complex-lookups-with-q-objects


29.1.2018 22.04 <eil...@themaii.org> kirjoitti:

--
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 django-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages