celery / django-celery-results

Celery result back end with django
Other
668 stars 206 forks source link

'result' cannot be specified for MyTaskResult model form as it is a non-editable field. Check fields/fieldsets/exclude attributes of class MyTaskResultAdmin. #394

Open chunkai-meng opened 1 year ago

chunkai-meng commented 1 year ago

If I use a proxy model and register MyTaskResultAdmin inherited from TaskResultAdmin,
will show the error above

found in django_celery_results.admin.TaskResultAdmin.get_readonly_fields

    def get_readonly_fields(self, request, obj=None):
        if ALLOW_EDITS:
            return self.readonly_fields
        else:
            return list({
                field.name for field in self.opts.local_fields    # will return [] even readonly_fields is set, which leads to the error
                # field.name for field in self.model._meta.fields    # Change to this fix the problem, but I'm not sure if this is the correct way
            })
auvipy commented 1 year ago

field.name for field in self.model._meta.fields should be the django API we should use

pr0fg commented 8 months ago

Can confirm the following change works as expected:

field.name for field in self.model._meta.fields