|
@@ -1,11 +1,12 @@
|
|
|
import random
|
|
|
+from django import forms
|
|
|
from django.urls import reverse
|
|
|
from django.utils.html import format_html, format_html_join
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
|
|
-from .models import *
|
|
|
-from .forms import PersonChangeForm
|
|
|
+from .models import Group, Person
|
|
|
+from .forms import PersonAdminForm
|
|
|
|
|
|
def random_color():
|
|
|
r = lambda: random.randint(0,255)
|
|
@@ -15,14 +16,14 @@ def random_color():
|
|
|
class PersonAdmin(admin.ModelAdmin):
|
|
|
list_select_related = ('parent', 'group')
|
|
|
list_display = ['name', 'get_partners', 'get_parent', 'birth_date', 'death_date', 'comment', 'color', 'group']
|
|
|
- list_editable = ['color']#, 'group']
|
|
|
+ list_editable = ['color']
|
|
|
list_filter = ('group', 'birth_date')
|
|
|
- search_fields = ['name', 'parent__name', 'partners__name']
|
|
|
+ search_fields = ['name', 'birth_date', 'birth_town', 'death_date', 'death_town', 'comment']
|
|
|
ordering = ('group','name')
|
|
|
filter_horizontal = ('partners',)
|
|
|
|
|
|
- fields = ('name', 'parent', 'partners', 'birth_date', 'birth_town', 'death_date', 'death_town', 'comment', 'image', 'image_tag', 'color', 'group', )
|
|
|
- readonly_fields = ('image_tag',)
|
|
|
+ fields = ('name', 'parent', 'partners', 'children', 'birth_date', 'birth_town', 'death_date', 'death_town', 'comment', 'image', 'image_tag', 'color', 'group')
|
|
|
+ readonly_fields = ('image_tag', 'children')
|
|
|
|
|
|
def get_queryset(self, request):
|
|
|
qs = super().get_queryset(request)
|
|
@@ -37,6 +38,9 @@ class PersonAdmin(admin.ModelAdmin):
|
|
|
return format_html('<a href="{}">{}</a>', reverse("admin:stammbaum_person_change", args=[obj.parent.id]), obj.parent)
|
|
|
get_parent.short_description = "Eltern"
|
|
|
|
|
|
+ def children(self, obj):
|
|
|
+ return format_html_join(', ', '<a href="{}">{}</a>', [(reverse("admin:stammbaum_person_change", args=[p.id]), p) for p in Person.objects.filter(parent=obj)])
|
|
|
+
|
|
|
def save_related(self, request, form, formsets, change):
|
|
|
super(PersonAdmin, self).save_related(request, form, formsets, change)
|
|
|
partners = form.instance.partners.all()
|
|
@@ -54,7 +58,7 @@ class PersonAdmin(admin.ModelAdmin):
|
|
|
partner.color = form.instance.color
|
|
|
partner.save()
|
|
|
|
|
|
- #form = PersonChangeForm
|
|
|
+ form = PersonAdminForm
|
|
|
|
|
|
@admin.register(Group)
|
|
|
class GroupAdmin(admin.ModelAdmin):
|