Hi,

I also had a couple of issues with Django's generic CBV.
My feeling is it raises a lot of frustration because it feels like there isn't 
much missing.
I've been playing with a few solutions to work around that.

I started a small proof of concept on chaining GCBV and a few other goodies.
I'm a bit reluctant to speak about it because *I'm not happy* with the way it 
currently is now.
The general idea was to be able to go as far as possible for newcomers without 
modifications.
To achieve that result, I took example on what forms and models already and 
used the same thing to chain mixins.

It currently what it looks like is.

1) define the mixins

class ProjectMixin(ObjectMixin):
    model = Project
    pk_url_kwarg = 'project_id'

    def get_queryset(self):
        return Project.objects.filter(members=self.request.user.id)

class BugMixin(ObjectMixin):
    model = Bug
    pk_url_kwarg = 'bug_id'

    def get_queryset(self):
        return = Bug.objects.filter(project=self.project)


2) define the views

class ProjectView(View):
    project = ProjectMixin(default_mode='detail')


class BugView(ProjectView):
    projects = ProjectMixin(mode='list')
    bug = BugMixin(default_mode='detail')


3) define the urls

urlpatterns = patterns('',
    url(r'^projects/$',
        ProjectView.as_view(mode='list'),
        name='projects'),
    url(r'^projects/new/$',
        ProjectView.as_view(mode='new'),
        name='new-project'),

....
)


A few things to notice.
View can inherit from the others.
Objects are "namespaces" in the view. See I get project (a single object) and 
projects (list of projects the user is member of) in the BugView.
You define only one view that you can specialize into list, detail, create, 
update, delete (although delete isn't implemented yet).


The current state for that:
- There's no documentation (as I said, I was a bit reluctant to do that mail 
because it is still a bit early)
- I recently switched from reusing the django's generic cbv to duplicating them 
in the code. A few implementation details still need to be cleaned.
- I'm not happy with the way I "specialize" the mixins according to the mode 
they should be in. I'm currently changing the mixin instance's heritage which I 
feel is *not* what I should do. I'll probably try to do something similar to 
what the forms do with BoundField
- I'm not happy with the way the "mode" is set too.
- Paginators have a semi working namespace. They *are* namespaced in the 
template, but aren't for the url part, this is work in progress.

Please keep that in mind if you have a look at the current code.

The "proof of concept" is there:
https://github.com/linovia/django-alternative-views

I wrote a demo project:
https://github.com/linovia/django-alternative-views/tree/master/demo

Tests should cover most (think it was around 90%) of the custom code. Since the 
inclusion of django generic cbv, it has droped but I'll see how I can play 
django's test for that part (not going to rewrite existing tests).


Regards,
Xavier Ordoquy,
Linovia.

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

Reply via email to