python - How to use validation to make a clickable, pseudo-readonly FileField in the admin? -
i'm trying have filefield clickable in admin readonly. there's open ticket issue, need workaround now. i'm trying write validator admin class i'm running exception when run it. have:
class modelwithattachment(models.model): attachment = filefield(upload_to=somewhere, blank=true) class modelwithattachmentadminform(forms.modelform): class meta: model = modelwithattachment def clean_attachment(self): attachment = self.cleaned_data['attachment'] return self.cleaned_data['attachment'] class modelwithattachmentadmin(admin.modeladmin): form = modelwithattachmentadminform
currently assertionerror no exception supplied @ line attachment = self.cleaned_data['attachment']
. if replace line cleaned_data = self.cleaned_data
, same assertionerror. far understand it, self.cleaned_data supposed have been created earlier in validation process, don't understand why doesn't seem exist.
secondly, goal whole scheme check value of attachment being submitted through admin against value holds, , reject (raise validationerror) if 2 differ - making attachment 'readonly' while allowing clicked in admin. feasible goal? there better/simpler way accomplish this?
i figured out. approach correct, clean_attachment
being defined as:
def clean_attachment(self): if 'attachment' in self.changed_data: raise forms.validationerror('no!') return self.cleaned_data['attachment']
the problem old .pyc file getting reused incorrectly. once deleted that, fine. hope helps else out.
Comments
Post a Comment