Solved. It seems this is due to the 1.2 alpha1 bug involving form.is_valid(): http://www.pubbs.net/django/201001/16447/ reverting to django 1.1 solved all my problems
On Wed, Jan 20, 2010 at 10:25, Massimiliano della Rovere < massimiliano.dellarov...@gmail.com> wrote: > Ok I managed to remove the compilatore field from the form (this > RowModelAdmin class is used by many Models, all having the compilatore > field) > def get_form(self, request, obj=None, **kwargs): > form = super(RowModelAdmin, self).get_form(request, obj, **kwargs) > if not request.user.is_superuser: > del form.base_fields['compilatore'] > return form > > Now the form validation sequence complains because the compilatore field is > part of the model and thus may not be empty (it's a ForeignKey to > auth.models.User). > I'm trying to override or customize the form.is_valid() method, so then I > will implement a > def save_model(self, request, obj, form, change): > obj = form.save(commit=False) > if obj.compilatore == None: > obj.compilatore = request.user.id > obj.save() > > Another way I tried was defining a RowModelForm for the RowModelAdmin > (adding "form = RowModelForm" in RowModelAdmin) class instead of impementing > get_form: > class RowModelForm(forms.ModelForm): > class Meta: > exclude = ('compilatore',) > def validate(self): > pass > def clean(self): > pass > def clean_compilatore(self): > return True > > But I still get the same error as above. > How can I hook to the validation process to tell it "close an eye on > compilatore being missing (when it is missing), I will add it later?" >--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.