How to add readonly inline on django admin

前端 未结 4 1017
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 13:01

I am using django 1.4 and I have a many2many field, so when creating the admin site I wanted to add this field as an inline, here is some code:

class SummaryInli         


        
4条回答
  •  走了就别回头了
    2021-02-01 14:05

    After a while of trying to find the name I figured out thanks to this answer, so I checked the names at self.opts.local_fields and found the name of the middle table and added it to readonly_fields, setting can_delete to False.

    class SummaryInline(admin.TabularInline):
        model = ParserError.summaries.through
        readonly_fields = ('myclasssummary',)
        can_delete = False
    

    pretty simple but took me a while so I figured out it was a good idea to add it here.

提交回复
热议问题