From f6d6b9c990dda3488c8ece5c09824767a36447cd Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 13 Jun 2012 01:42:45 +0000 Subject: [PATCH] Temp fix for loading too many people for father/mother on Family edit page. Need to have an auto-complete solution svn: r19836 --- src/webapp/grampsdb/forms.py | 9 +++++++++ src/webapp/grampsdb/models.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py index 8e4f46544..bde965fa7 100644 --- a/src/webapp/grampsdb/forms.py +++ b/src/webapp/grampsdb/forms.py @@ -127,6 +127,15 @@ class FamilyForm(forms.ModelForm): model = Family exclude = ["handle"] + def __init__(self, *args, **kwargs): + super(FamilyForm, self).__init__(*args, **kwargs) + self.fields['father'].queryset = Person.objects.filter( + gender_type=get_type_from_name(GenderType, "Male")) \ + .order_by("name__surname__surname", "name__first_name") + self.fields['mother'].queryset = Person.objects.filter( + gender_type=get_type_from_name(GenderType, "Female")) \ + .order_by("name__surname__surname", "name__first_name") + class EventForm(forms.ModelForm): class Meta: model = Event diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index 8b17aa857..b82f1044d 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -42,6 +42,16 @@ from webapp.grampsdb.profile import Profile # #--------------------------------------------------------------------------- +def get_type_from_name(the_type, name): + """ + Gets the type for a given name. + >>> get_type_from_name(GenderType, "Female") + + >>> get_type_from_name(GenderType, "Male") + + """ + return the_type.objects.get(name=name) + def get_type(the_type, data, get_or_create=False): """ Gets the default row for a given Type and data. Data is