Django Admin nested inline

前端 未结 6 1182
耶瑟儿~
耶瑟儿~ 2020-12-01 02:30

I need a nested django admin inline, which I can include the date field inlines in an other inline like below.

I have the models below:

class Person         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 03:16

    I used the solution provided by @bigzbig (thank you).

    I also wanted to go back to the first list page once changes had been saved so added:

    class MyModelInline(EditLinkToInlineObject, admin.TabularInline):
        model = MyModel
        readonly_fields = ('edit_link', )
    
        def response_post_save_change(self, request, obj):
            my_second_model_id = MyModel.objects.get(pk=obj.pk).my_second_model_id
            return redirect("/admin/mysite/mysecondmodel/%s/change/" % (my_second_model_id))
    

提交回复
热议问题