diff --git a/src/data/templates/view_family_detail.html b/src/data/templates/view_family_detail.html
index 37b882ad8..838c3c910 100644
--- a/src/data/templates/view_family_detail.html
+++ b/src/data/templates/view_family_detail.html
@@ -106,7 +106,7 @@
- {% children_table family user action "/family/%s/children/$act" family.handle %}
+ {% children_table family user action "/person/$act/family/%s" family.handle %}
{% event_table family user action "/event/$act/family/%s" family.handle %}
diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py
index 2df8d671b..64425724a 100644
--- a/src/webapp/grampsdb/models.py
+++ b/src/webapp/grampsdb/models.py
@@ -854,7 +854,7 @@ class RepositoryRef(BaseRef):
class PersonRef(BaseRef):
ref_object = models.ForeignKey('Person')
- description = models.CharField(max_length=50)
+ description = models.CharField(max_length=50, blank=True, null=True)
def __unicode__(self):
return "PersonRef to " + str(self.ref_object)
diff --git a/src/webapp/grampsdb/view/person.py b/src/webapp/grampsdb/view/person.py
index 5e46f14e4..ec001ed29 100644
--- a/src/webapp/grampsdb/view/person.py
+++ b/src/webapp/grampsdb/view/person.py
@@ -351,7 +351,7 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
return redirect("/person/%s" % build_search(request))
elif action in ["save", "create"]: # could be create a new person
# look up old data, if any:
- if handle:
+ if handle:
person = Person.objects.get(handle=handle)
name = person.name_set.get(preferred=True)
surname = name.surname_set.get(primary=True)
@@ -391,13 +391,16 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False? Remove from form?
surname.save()
- dji.rebuild_cache(person)
- if add_to:
- item, handle = add_to
- model = dji.get_model(item)
- obj = model.objects.get(handle=handle)
- dji.add_person_ref_default(obj, person)
+ if add_to: # Adding a child to the family
+ item, handle = add_to # ("Family", handle)
+ model = dji.get_model(item) # what model?
+ obj = model.objects.get(handle=handle) # get family
+ dji.add_child_ref_default(obj, person) # add person to family
+ person.parent_familes.add(obj) # add family to child
+ dji.rebuild_cache(person) # rebuild child
+ dji.rebuild_cache(obj) # rebuild family
return redirect("/%s/%s%s" % (item, handle, build_search(request)))
+ dji.rebuild_cache(person)
return redirect("/person/%s%s" % (person.handle, build_search(request)))
else:
# need to edit again
diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py
index 7a9cf1c22..8babc9f13 100644
--- a/src/webapp/grampsdb/views.py
+++ b/src/webapp/grampsdb/views.py
@@ -423,7 +423,7 @@ def add_to(request, view, item, handle):
Add a new referenced from - .
"""
# /view/add/person/handle
- return action(request, view, handle, "add", (item, handle))
+ return action(request, view, None, "add", (item, handle))
def action(request, view, handle, action, add_to=None):
"""
diff --git a/src/webapp/libdjango.py b/src/webapp/libdjango.py
index 6ae1ef2cd..fd494d55c 100644
--- a/src/webapp/libdjango.py
+++ b/src/webapp/libdjango.py
@@ -879,6 +879,17 @@ class DjangoInterface(object):
self.add_media_ref_list(citation, media_list)
self.add_citation_datamap_dict(citation, datamap)
+ def add_child_ref_default(self, obj, child, frel=1, mrel=1, private=False):
+ object_type = ContentType.objects.get_for_model(obj) # obj is family
+ count = models.ChildRef.objects.filter(object_id=obj.id,object_type=object_type).count()
+ child_ref = models.ChildRef(private=private,
+ referenced_by=obj,
+ ref_object=child,
+ order=count + 1,
+ father_rel_type=models.get_type(models.ChildRefType, frel), # birth
+ mother_rel_type=models.get_type(models.ChildRefType, mrel))
+ child_ref.save()
+
def add_child_ref(self, obj, data):
(private, citation_list, note_list, ref, frel, mrel) = data
try:
diff --git a/src/webapp/utils.py b/src/webapp/utils.py
index 737b6e9b4..a3719cacc 100644
--- a/src/webapp/utils.py
+++ b/src/webapp/utils.py
@@ -840,7 +840,8 @@ def children_table(obj, user, action, url=None, *args):
table.links(links)
retval += table.get_html()
if user.is_superuser and url and action == "view":
- retval += make_button(_("Add Child"), (url % args))
+ retval += make_button(_("Add Child"), (url.replace("$act", "add") % args))
+ retval += make_button(_("Share Child"), (url.replace("$act", "share") % args))
else:
retval += nbsp("") # to keep tabs same height
return retval