Django: Faking a field in the admin interface?

后端 未结 4 2113
轻奢々
轻奢々 2021-01-30 19:00

I have a model, Foo. It has several database properties, and several properties that are calculated based on a combination of factors. I would like to present these

4条回答
  •  天命终不由人
    2021-01-30 19:09

    It's easy enough to get arbitrary data to show up in change list or make a field show up in the form: list_display arbitrarily takes either actual model properties, or methods defined on the model or the modeladmin, and you can subclass forms.ModelForm to add any field type you'd like to the change form.

    What's far more difficult/impossible is combining the two, i.e. having an arbitrary piece of data on the change list that you can edit in-place by specifying list_editable. Django seems to only accept a true model property that corresponds to a database field. (even using @property on the method in the model definition is not enough).

    Has anyone found a way to edit a field not actually present on the model right from the change list page?

提交回复
热议问题