I want to populate a field before validation in admin.
models.py
class Ad(models.Model):
.....
manual_code = models.BooleanField("Manual Code", default=False)
code = models.TextField("Code")
admin.py
class MyAdAdminForm(forms.ModelForm):
class Meta:
model = Ad
def clean(self):
cleaned_data = self.cleaned_data
cleaned_data['code'] = "dadad"
print cleaned_data
return cleaned_data
class AdAdmin(admin.ModelAdmin):
form = MyAdAdminForm
admin.site.register(Ad, AdAdmin)
eventually I wanna generate that whole "code" field, but I'm still getting the error in admin that the field is empty although I can see the value of it ("dadad") in the shell.
I also tried
def clean_code(self):
and it wasn't calling that function at all.
and I also tried
def save_model(request,....):
in the AdAdmin class but it wasn't calling that either.
so what should I do?