Reputation: 8836
I have a model whose admin is as follows:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('invoice_code', 'total_amount', 'paid', )
list_editable = ('paid', )
search_fields = ('invoice_code', )
def __init__(self, *args, **kwargs):
super(MyModelAdmin, self).__init__(*args, **kwargs)
self.list_display_links = (None, )
Here the field paid is a booleanfield and by default it will be unchecked. What I want to achieve is, the field paid should be editable when it is unchecked and should be readonly when it is checked. I want to achieve this in list_editable. Is it possible to achieve this? If so, how to do it? Thanks is advance.
Upvotes: 3
Views: 701
Reputation: 31
As far as I can tell you can only use default fields in list_editable. These fields only support standard behaviours assocated with these default fields. In addition, the operations you can perform on records in a table are equal to one another.
If you would want to achieve custom behaviour on a row to row basis, I believe you would have to implement a function into your model which returns a field that is editable if checked, and uneditable when unchecked. This would simply be a matter of returning an html checkbox that is either active or not based on the class you provide it and some JS. You could also implement this directly into an input checkbox that has a disabled attribute.
In order to update the checkbox and the specified field though, you'd have to either update the values to the backend through an ajax POST command (through Jquery or something else), or you'd have to alter the behaviour of the form/view and would have to update by saving.
Hope this helps.
Upvotes: 2