How to prevent self (recursive) selection for FK / MTM fields in the Django Admin

后端 未结 3 1776
余生分开走
余生分开走 2021-01-04 08:46

Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to \'self\' how can I prevent self (recursive) selection within the Djan

3条回答
  •  清歌不尽
    2021-01-04 09:30

    You can use a custom ModelForm in the admin (by setting the "form" attribute of your ModelAdmin subclass). So you do it the same way in the admin as you would anywhere else.

提交回复
热议问题