Re: error message in admin
On Tue, Aug 18, 2009 at 4:45 PM, Marek Palatinus wrote: > On Tue, Aug 18, 2009 at 4:36 PM, Joshua Russo wrote: >> On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus wrote: >>> >>> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo >>> wrote: >>> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus >>> > wrote: >>> >> >>> >> Hello, >>> >> >>> >> Im doing some validation in ModelAdmin.save_model(). I can cancel >>> >> operation (just dont call parent method), but I also need to show some >>> >> error message to user. Im able to call self.message_user() and show >>> >> INFO message, but how to send ERROR message and maybe show form back >>> >> and force user to correct inputs? >>> >> >>> >> I need validation on level of whole formset, not on field level, so I >>> >> cannot use some custom field to achieve that. >>> > >>> > What you want is to override the ModelAdmin.form with a custom form and >>> > handle the clean_xxx() methods there. Django form validation is done in >>> > the >>> > form objects/classes. >>> > Create a ModelForm >>> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then >>> > set >>> > your ModelAdmin.form to your new ModelForm. >>> > >>> >>> Joshua, thanks a lot! >>> >>> to others: there also exists clean() which have available all fields >>> from form at one place. Im sending working code for others: class SlugModelForm(ModelForm): def clean_slug(self, *args): if not self.instance.allow_slug_slashes and self.data['slug'].find('/') != -1: msg = _("Slash '/' is not allowed here.") self.errors['slug'] = ErrorList([msg]) return self.data['slug'] class BaseModuleAdmin(admin.ModelAdmin): list_editable = ('enabled',) exclude = ('site', ) form = SlugModelForm Im using slug as universal identifier across tens modules inside application, but in some rare cases I want to allow slashes inside slugs (=full urls). Construction above is logic for showing error message to user, when he write slash to module's slug, which have disabled this feature. Regards, Marek --~--~-~--~~~---~--~~ 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: error message in admin
On Tue, Aug 18, 2009 at 4:36 PM, Joshua Russo wrote: > On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus wrote: >> >> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo >> wrote: >> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus >> > wrote: >> >> >> >> Hello, >> >> >> >> Im doing some validation in ModelAdmin.save_model(). I can cancel >> >> operation (just dont call parent method), but I also need to show some >> >> error message to user. Im able to call self.message_user() and show >> >> INFO message, but how to send ERROR message and maybe show form back >> >> and force user to correct inputs? >> >> >> >> I need validation on level of whole formset, not on field level, so I >> >> cannot use some custom field to achieve that. >> > >> > What you want is to override the ModelAdmin.form with a custom form and >> > handle the clean_xxx() methods there. Django form validation is done in >> > the >> > form objects/classes. >> > Create a ModelForm >> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then >> > set >> > your ModelAdmin.form to your new ModelForm. >> > >> >> Joshua, thanks a lot! >> >> to others: there also exists clean() which have available all fields >> from form at one place. > > I often also place checks in the save of a model (like you were doing) to > help catch scenarios when using the models in your own code (outside of the > admin app). Yes, I know that and Im using model validation, but I need check human input and print errors to admin interface. When I have validation only in model, there is no chance to print error message (because it can be called outside admin). Marek --~--~-~--~~~---~--~~ 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: error message in admin
On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus wrote: > > On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo > wrote: > > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus > wrote: > >> > >> Hello, > >> > >> Im doing some validation in ModelAdmin.save_model(). I can cancel > >> operation (just dont call parent method), but I also need to show some > >> error message to user. Im able to call self.message_user() and show > >> INFO message, but how to send ERROR message and maybe show form back > >> and force user to correct inputs? > >> > >> I need validation on level of whole formset, not on field level, so I > >> cannot use some custom field to achieve that. > > > > What you want is to override the ModelAdmin.form with a custom form and > > handle the clean_xxx() methods there. Django form validation is done in > the > > form objects/classes. > > Create a ModelForm > > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then > set > > your ModelAdmin.form to your new ModelForm. > > > > Joshua, thanks a lot! > > to others: there also exists clean() which have available all fields > from form at one place. I often also place checks in the save of a model (like you were doing) to help catch scenarios when using the models in your own code (outside of the admin app). --~--~-~--~~~---~--~~ 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: error message in admin
On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo wrote: > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus wrote: >> >> Hello, >> >> Im doing some validation in ModelAdmin.save_model(). I can cancel >> operation (just dont call parent method), but I also need to show some >> error message to user. Im able to call self.message_user() and show >> INFO message, but how to send ERROR message and maybe show form back >> and force user to correct inputs? >> >> I need validation on level of whole formset, not on field level, so I >> cannot use some custom field to achieve that. > > What you want is to override the ModelAdmin.form with a custom form and > handle the clean_xxx() methods there. Django form validation is done in the > form objects/classes. > Create a ModelForm > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then set > your ModelAdmin.form to your new ModelForm. > Joshua, thanks a lot! to others: there also exists clean() which have available all fields from form at one place. Regards, Marek --~--~-~--~~~---~--~~ 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: error message in admin
On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus wrote: > > Hello, > > Im doing some validation in ModelAdmin.save_model(). I can cancel > operation (just dont call parent method), but I also need to show some > error message to user. Im able to call self.message_user() and show > INFO message, but how to send ERROR message and maybe show form back > and force user to correct inputs? > > I need validation on level of whole formset, not on field level, so I > cannot use some custom field to achieve that. > What you want is to override the ModelAdmin.form with a custom form and handle the clean_xxx() methods there. Django form validation is done in the form objects/classes. Create a ModelForm ( http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then set your ModelAdmin.form to your new ModelForm. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
error message in admin
Hello, Im doing some validation in ModelAdmin.save_model(). I can cancel operation (just dont call parent method), but I also need to show some error message to user. Im able to call self.message_user() and show INFO message, but how to send ERROR message and maybe show form back and force user to correct inputs? I need validation on level of whole formset, not on field level, so I cannot use some custom field to achieve that. Thanks, Marek --~--~-~--~~~---~--~~ 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: Error message in admin - row level permissions
A victim of my own cleverness! Part of the row permissions was to prevent the owner changing ownership, so I had this in the admin form: def get_fieldsets(self, request, obj=None): if request.user.is_superuser or request.user.has_perm ('town.admin_business'): fields=[ (None, {'fields': ['tourism','community','cat','name','is_live','paid','owner']}), ] else: fields=[ (None, {'fields': ['tourism','community','cat','name','is_live','paid']}), ] return fields So the form is generating an error that owner is not filled in, but because owner is not on the form there is nowhere to display it! Mystery solved. So now trying to work out how to pass the owner info to the admin form. Tried hidden_fields, but this not available in version 1.0 of Django. On May 9, 9:18 am, phoebebright wrote: > I have almost implemented a row level permissions facilitiy for a > model in my app. > > I can change the owner of the record > Display only their records in admin > But when logged in as the owner and click Save on the edit screen I > get the error "Please correct the error below." but no indication of > what the error is. If I log in with permissions to change the table > or as superuser I don't get this error, so I assume there is some > permissions checking going on somewhere. > > In an attempt to find where the problem is I have: > > in admin.py > > def has_change_permission(self, request, obj=None): > return True > > def save_model(self, request, obj, form, change): > ''' > do nothing > ''' > > Nothing makes a difference. Any suggestions as to where to look very > welcome as am stumped! --~--~-~--~~~---~--~~ 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: Error message in admin - row level permissions
Is this a clue? Got this info from forcing an error at the top of the form. Permissions are correct but seems to think there is a field missing, but not saying which one. Tried making sure there is data in every field but still no change. Just to confirm, I can save this with a user with table permissions. (['admin/town/business/change_form.html', 'admin/town/ change_form.html', 'admin/change_form.html'], {'add': False, 'adminform': , 'app_label': 'town', 'change': True, 'content_type_id': 45L, 'errors': [u'This field is required.'], 'form_url': '', 'has_absolute_url': True, 'has_add_permission': False, 'has_change_permission': True, 'has_delete_permission': False, 'has_file_field': True, 'inline_admin_formsets': [], 'is_popup': False, 'media': '\n\n\n\n\n\n', 'object_id': u'86', 'opts': , 'ordered_objects': [], 'original': , 'root_path': u'/admin/', 'save_as': False, 'save_on_top': False, 'title': u'Change Business Directory'}) On May 9, 9:18 am, phoebebright wrote: > I have almost implemented a row level permissions facilitiy for a > model in my app. > > I can change the owner of the record > Display only their records in admin > But when logged in as the owner and click Save on the edit screen I > get the error "Please correct the error below." but no indication of > what the error is. If I log in with permissions to change the table > or as superuser I don't get this error, so I assume there is some > permissions checking going on somewhere. > > In an attempt to find where the problem is I have: > > in admin.py > > def has_change_permission(self, request, obj=None): > return True > > def save_model(self, request, obj, form, change): > ''' > do nothing > ''' > > Nothing makes a difference. Any suggestions as to where to look very > welcome as am stumped! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Error message in admin - row level permissions
I have almost implemented a row level permissions facilitiy for a model in my app. I can change the owner of the record Display only their records in admin But when logged in as the owner and click Save on the edit screen I get the error "Please correct the error below." but no indication of what the error is. If I log in with permissions to change the table or as superuser I don't get this error, so I assume there is some permissions checking going on somewhere. In an attempt to find where the problem is I have: in admin.py def has_change_permission(self, request, obj=None): return True def save_model(self, request, obj, form, change): ''' do nothing ''' Nothing makes a difference. Any suggestions as to where to look very welcome as am stumped! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Add error message in admin app. icon_error
Hi everybody! I'm starting to play around with django and I'm building a simple application with the admin app using admin actions. Every time user uses an admin action, a message shows up confirming the action was successfully exceuted: self.message_user(request, "Action was succesfully executed") This shows up a message on green backgroupnd with an ok mark When I find an error I show: self.message_user(request, "¡¡¡ERROR !!!") which for me is wrong, as I show an error message on green with an icon_success.gif I've searched everywhere, but I couldn't find how to display an error message on red with icon_error. It seems this should be straightforward, but I can't find out. Thanks in advance --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
seemingly spurious "Unknown table 'store_itemgroups' in order clause" error message in admin
I have the following class as one of my model classes: class OrderDetail(meta.Model): item_group = meta.OneToOneField(itemgroups.ItemGroup) parents_names = meta.CharField(maxlength=100) birth_date = meta.CharField(maxlength=100) birth_time = meta.CharField(maxlength=100) birth_weight = meta.CharField(maxlength=100) birth_length = meta.CharField(maxlength=100) announcement_text = meta.CharField(maxlength=100) other_instructions = meta.CharField(maxlength=100) color = meta.CharField(maxlength=100) copyright_release = meta.CharField(maxlength=100) def __repr__(self): return self.parents_names class META: admin = meta.Admin() When I try to view the admin page for this class, I get: OperationalError at /admin/store/orderdetails/ (1109, "Unknown table 'store_itemgroups' in order clause") Request Method: GET Request URL:http://localhost:8000/admin/store/orderdetails/ Exception Type: OperationalError Exception Value:(1109, "Unknown table 'store_itemgroups' in order clause") Exception Location: /usr/local/apps/python2.4/lib/python2.4/site-packages/MySQL_python-1.2.0-py2.4-linux-i686.egg/MySQLdb/connections.py in defaulterrorhandler, line 32 It's complaining about the store_itemgroups table not existing, but it exists. Here is the class definition: class ItemGroup(meta.Model): #product_group_name = meta.CharField(maxlength=100) product_group = meta.ForeignKey(ProductGroup) customer_order = meta.ForeignKey(CustomerOrder) def __repr__(self): return self.get_product_group().name #return self.product_group_name class META: admin = meta.Admin() and I can see it in PhpMyAdmin and have inserted data into it through Django. This may not be a big deal since I'm probably going to tie these two classes to one parent class, but I'd still be interested in seeing this work as I think it ought to. - jmj