Hi, I need to manipulate my pk when using new class based views. In
order to DRY I think what's needed is to superclass SingleObjectMixin.

I have the following but it's not working. Greatly appreciate help/
suggestions!

In view.py have the below which does not work.

from django.views.generic.detail import SingleObjectMixin
class SingleObjectMixin(SingleObjectMixin):

    def get_object(self, *args, **kwargs):
        queryset = self.get_queryset()
        pk = pid_to_oid(self.kwargs.get('pk'))
        queryset = queryset.filter(pk=pk)
        obj = queryset.get()
        return obj

        return super(SingleObjectMixin,self).get_object(self, *args,
**kwargs)

from django.views.generic import ListView, DetailView

but if I do the below it works(but prefer to not have to add this to
each CBV).

class ItemDetailView(DetailView):
    model=Item

    def get_object(self):
        queryset = self.get_queryset()
        pk = pid_to_oid(self.kwargs.get('pk'))
        queryset = queryset.filter(pk=pk)
        obj = queryset.get()
        return obj

Thanks in advance for the help.

Dave






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to