How do I get the actual object id in a Django admin page (inside formfield_for_foreignkey)?

后端 未结 7 969
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 09:59

I \'ve already solved the problem of getting the object id being edited using this code:

class CompanyUserInline(admin.StackedInline):
    \"\"\"
    Defines         


        
7条回答
  •  清歌不尽
    2020-12-15 10:13

    As far as i know it is not possible to access the current instance through the formfield_for_...-methods, because they will only be called for a single field instance!

    A better point to hook into this logic where you can access the whole instance/form would be get_form. You can also overwrite a form field's queryset there!

提交回复
热议问题