Custom list_editable field in django admin change list, which doesn't correspond directly to a model field

后端 未结 3 613
攒了一身酷
攒了一身酷 2020-12-31 15:38

Assuming my model looks like this (this is a simplified example):

class Person(Model):
  first_name = CharField(...)
  last_name = CharField(...)

  def nam         


        
3条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 16:07

    I just tried a quick mock-up of the problem in the admin. It seems that the admin validation fails for a field which is in list_editable that is not defined on the model. In short, the answer to your question seems to be no.

    However, that doesn't mean it's not doable. With a bit of Javascript, you could use X-editable

    (or roll your own), and make the "Name" column editable. Create a view to validate the data and save it to the model. Set X-editable field 'url' parameter to post to this URL. Obviously decorate your view with login_required / permissions_required etc, to make sure no-one else can edit the data.

提交回复
热议问题