Re: Trouble raising forms.ValidationError in save() override in admin.py

2018-05-03 Thread Gonzalo Amadio
This is very old, but in the case someone red this.

If you do it on the save method of the admin, you MUST save the model.

So you should override admin's form. 

Check it here how to do it : http://itegram.com/2018/05/03/
add-extra-control-to-admin-save-method/ 


El jueves, 31 de marzo de 2011, 8:10:40 (UTC-3), Daniel Roseman escribió:
>
> On Thursday, March 31, 2011 11:09:17 AM UTC+1, Lloyd Dube wrote:
>>
>> Hi Shawn,
>>
>> Thanks for the feedback. I read the docs and defined a clean_audio_file 
>> method in my ModelAdmin class.
>
>
> That's not what the docs say. They say you should create it on the Form. 
> And where did you get the idea that the clean method takes any of those 
> parameters?
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b73a0f49-2716-42f1-b026-6dd3a935d8fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble raising forms.ValidationError in save() override in admin.py

2011-03-31 Thread Daniel Roseman
On Thursday, March 31, 2011 11:09:17 AM UTC+1, Lloyd Dube wrote:
>
> Hi Shawn,
>
> Thanks for the feedback. I read the docs and defined a clean_audio_file 
> method in my ModelAdmin class.


That's not what the docs say. They say you should create it on the Form. And 
where did you get the idea that the clean method takes any of those 
parameters?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: Trouble raising forms.ValidationError in save() override in admin.py

2011-03-31 Thread Sithembewena Lloyd Dube
Hi Shawn,

Thanks for the feedback. I read the docs and defined a clean_audio_file
method in my ModelAdmin class. I dropped the Podcast table, made the field
not mandatory in the model and did a syncdb (to test my clean method).

Still a podcast can be saved without the audio_file: the code in the clean
method does not appear to run. Please see the code below:

class PodcastAdmin(admin.ModelAdmin):
 list_display = ('title', 'audio_file', 'active', 'user')

 def clean_audio_file(self, request, obj, form, change):
  data = self.cleaned_data['audio_file']
  if not data or len(data) < 1 or data == "":
   raise forms.ValidationError("Provide a file!")
  return data

admin.site.register(Podcast, PodcastAdmin)

Am at a loss.

On Wed, Mar 30, 2011 at 4:37 PM, Shawn Milochik  wrote:

> No, the forms.ValidationError has to be raised in one of the clean()
> methonds of your model. Otherwise it will result in a stack trace.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@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.
>



-- 
Regards,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: Trouble raising forms.ValidationError in save() override in admin.py

2011-03-30 Thread Shawn Milochik
No, the forms.ValidationError has to be raised in one of the clean()
methonds of your model. Otherwise it will result in a stack trace.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.