Hi,

I looked for django-announcements to post this in, but didn't find at
groups.google.com. If this is not the place for such announcements I'm
sorry. Anyway;

Being somewhat underwhelmed by class based views due to the repetative
coding in urls.py etc I tried to see if I could get generic
scaffolding and basic views up and running based on a given model in
less lines of code. It's pretty simple and not heavily tested, but I'd
like to see if any of you has any inital comments before I spend a lot
of time on it.

The idea is that we always write the same views for alot of our
models; a list view, a detail view and add/update/delete. My
app/urls.py seem to have repeating patterns for all these views.
Generic views, class based or plain functions, do help but I still
find all the coding a bit redundant. In essence the templates are the
only thing that I really have to code manually.

Using quickview you define your model like so :


    class Person(models.Model):
        name = models.CharField(max_length=30)
        age = models.IntegerField(default=10)

In views.py:

    from models import Person
    from quickview import QuickView

    class PersonView(QuickView):
        model = Person

And in urls.py:

    from views import PersonView

    # after your other patterns:
    urlpattern += YourView.get_urls()


After a little syncdb and runserver you'll have an urlconfig/pattern
something like this:

myapp/person/list/$ [name='myapp-person-list']
myapp/person/add/$ [name='myapp-person-add']
myapp/person/(?P<pk>\d+)/$ [name='myapp-person-detail']
myapp/person/update/(?P<pk>\d+)/$ [name='myapp-person-update']
myapp/person/delete/(?P<pk>\d+)/$ [name='myapp-person-delete']

where myapp is the app my person-models resides in. Now you define
some templates ( list.html, detail.html, add.html, update.html,
delete.html ) in /templates/myapp/person/ and you're good to go ;-).


Todos: user authentication/login_required etc. and unittests.

The code is available at pypi ( pip install django-quickview ) or you
can browse the source at
https://bitbucket.org/weholt/django-quickview. The testsite-folder at
bitbucket contains a working example.

-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to