python - Django admin - remove "add another" button for a self-referential field -


i have django project includes model class optional self-referential foreignkey field. partial snippet:

class site(models.model):     name = models.charfield(max_length=100)     parent_site = models.foreignkey('self', null=true, blank=true) 

i'm using django admin site create new objects. class' admin form i'd disable "add another..." button next parent_site field (i.e. when you're creating new site, can't open popup create new site parent).

i can't remove has_add_permission user, need in current add view. don't mind removing function both add , change views, limiting removal add view helpful.

i haven't been able work out how use inline field classes achieve this, or formfield_for_foreignkey, or custom modelform. got solution more elegant using javascript on customised form template?

no css hacks add admin class:

max_num=0 

or try in admin.py ( older django versions):

class model_admin(admin.modeladmin):     class media:         css = {'all': ('css/no-addanother-button.css',)} 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -