rhblind / django-gcharts

Provides a QuerySet, Manager and other tools for easy integration with the Google Visualization API
Other
41 stars 14 forks source link

Unable to use the Django admin app to delete an object that uses GChartsManager #3

Closed palewis closed 11 years ago

palewis commented 11 years ago

I have an object that starts like this:

class MyClass( models.Model ):
    gcharts = GChartsManager()
    objects = models.Manager()

When I use the admin app to try to delete such an object, I get the following traceback:

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, _callback_args, *_callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
  2. return self.admin_site.admin_view(view)(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  3. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  4. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  5. return view(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
  6. return bound_func(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  7. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
  8. return func(self, _args2, *_kwargs2) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view
  9. response = self.response_action(request, queryset=cl.get_query_set(request)) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in response_action
  10. response = func(self, request, queryset) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/actions.py" in delete_selected
  11. queryset.delete() File "/usr/local/lib/python2.7/dist-packages/gcharts/init.py" in delete
  12. raise NotImplementedError("GChartsQuerySet is not able to modify the database")
rhblind commented 11 years ago

Hello,

I'm unable to reproduce this issue of my own. Can you please provide additional examples? Do you use any custom delete methods in your ModelAdmin class? From your error message it seems like you are using the GChartsQuerySet to manage your delete, which are not supported. That's why you need to set up both the objects = models.Manager() and the gcharts = GChartsManager() which it seems like you have done correctly.

As long as you make sure the delete is executed with the objects manager, everything should be fine, but as far as I can see from the tracelog, the delete is beeing executed through the gcharts manager.

palewis commented 11 years ago

Do you use any custom delete methods in your ModelAdmin class?

No

From your error message it seems like you are using the GChartsQuerySet to manage your delete

I am not doing so explicitly. I'm using the stock 'admin' app that comes with Django to attempt to delete the object. Is it possible that the Django admin app is selecting the wrong model manager for delete? Or perhaps it iterates all managers when executing delete?

rhblind commented 11 years ago

Hello, Sorry for long response time, been a bit busy with christmas stuff around here. I have now set up a small project from scratch here to try to figure out what's going on, and it seems like django are using the first specified manager in your model as the default manager.

So your code should work if you define your managers like this:

class MyModel(models.Model):

    objects = models.Manager()
    gcharts = GChartsManager()

    ....

and not the other way around. I will provide a fix the next few days.