Need to create an edit box connected to one table field

25 views
Skip to first unread message

eil...@themaii.org

unread,
Jan 19, 2018, 10:56:01 PM1/19/18
to Django users


I need to create an edit box called handicapped with three drop down options on the display:
  0 - none
  1 - Mental
  2 - Phyiscal

and connect it to the handicapped field init(11) in the family database

I know I have to do something like:

            if form['handicapped'].data == 1 or 2:
                q = context['child_filter'].filter(Q(handicapped=handicapped_dict[request.POST['handicapped']]))

# start of output using search parameters

            if q.count() > 1:
              search_message = "There are %s children that match your selection of %s"  %  (q.count(), request.POST['gender'])
            else:
              search_message = "There is 1 child that matches your selection of %s"  %  (request.POST['gender'])

            if q.count() > 1:
               search_message = ", age: %s"  %  (request.POST['age'])
            else:
               search_message = ", age: %s"  % (request.POST['age'])

            if form.data['handicapped'] is 'Physical' or 'Mental':
               if q.count() > 1:
                  search_message = ", is %s handicapped" %  (request.POST['handicapped'])
               elif q.count() == 1:
                  search_message = ", is %s handicapped" % (request.POST['handicapped'])
            else:
                search_message = ", are %s handicapped" % (request.POST['handicapped'])

but it doesn't _work at all_.

The database is defined all right, I should say.

I get lots of different types of errors - sorry I can't include them now, but definitely not week if the problem is still outstanding.

-Eileen

Costja Covtushenko

unread,
Jan 20, 2018, 2:54:15 AM1/20/18
to django...@googlegroups.com
Hi Eileen,

Can you please elaborate a little bit?
Do you use Form? Can you provide its code?

Also sorry but it is not clear what are you trying to achieve with those value?
Is it for searching data in DB?

Regards,
Constantine C.

On Jan 19, 2018, at 5:08 PM, eil...@themaii.org wrote:

handicapped

eil...@themaii.org

unread,
Jan 22, 2018, 4:56:22 PM1/22/18
to Django users
Yes, I use Form. Here's it's contents:
from django import forms
from .widgets import ChainedSelectWidget
from .models import Child


class SponsorForm(forms.Form):
    child = forms.IntegerField()


class FilterForm(forms.Form):
    gender = forms.ChoiceField(choices=[(x, x) for x in ('-----', 'MALE', 'FEMALE')], required=False)
    age = forms.ChoiceField(choices=[(x, x) for x in range(1, 18)], required=False)
#    orphaned = forms.BooleanField(initial=False,required=False)
#    extreme_need = forms.BooleanField(initial=False,required=False)
    handicapped = forms.ChoiceField(choices=[(x, x) for x in ('-------', 'Mental', 'Physcal')], required=False)

    def __init__(self, *args, **kwargs):
        super(FilterForm, self).__init__(*args, **kwargs)

        if 0 == len(self.data):
            self.fields['age'].queryset = Child.objects.none()

        # assign a widget to second select field
        self.fields['age'].widget = ChainedSelectWidget(
            parent_name='gender',         # the name of parent field
            app_name='sponsorship',            # the name of model's application
            model_name='child',          # the name of a model with the method
            method_name='get_children',  # the name of queryset method
            )

It is for finding a child who may or may not have one of two types of handicaps.


-Eileen
Reply all
Reply to author
Forward
0 new messages