:::: MENU ::::

The Project: Django URLs

Okay, I’ve added the generic views for the podcast list and the podcast detail. These were fairly simple once you looked at the right examples and documentation online. I’d like to say that the create_object and update_object generic views were working as well. I’ve got the create_object working, but the update_object won’t work. If anyone has a clue on how to implement the update_object generic view, leave a comment and I’d be eternally grateful. If I don’t get any suggestions, I’ll post the code in a few days even if it’s not working and hope for a response.

Here’s the urls.py file that creates the list and details:

from django.conf.urls.defaults import *
from podcastersfriend.podcast.models import Podcast
from django.views.generic.simple import direct_to_template
from django.views.generic import list_detail
from django.views.generic.create_update import create_object, update_object
from django.views import static
import podcastersfriend.podcasts.views

podcast_list_info = {
    "queryset" : Podcast.objects.all(),
}

podcast_detail_info = {
    "queryset" : Podcast.objects.all(),
    "template_object_name" : "podcast",
}

podcast_add_info = {
     "model" : Podcast,
     "post_save_redirect" : "/podcasts"
}

podcast_update_info = {"model" : Podcast }

urlpatterns = patterns('',

     (r'^$', podcastersfriend.podcasts.views.indexPage),
     (r'^admin/', include('django.contrib.admin.urls')),
     (r'^podcasts/?$', list_detail.object_list, podcast_list_info),
     (r'^podcasts/(?P<object_id>d+)/?$', list_detail.object_detail,podcast_detail_info),
     (r'^podcasts/add/?$', create_object, podcast_add_info),
     (r'^podcasts/edit/(?P<object_id>d+)/?$', update_object, podcast_update_info),
     (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'c:/projects/podcastersfriend/podcast/static'}),
)

Here’s a link to the file: Django URLs

If you see something wrong with this, please leave a comment explaining why and how I might make it better. The templates are working as well, except for they don’t validate the data being entered yet. That will be the next step, and I’ll post the templates in a couple of days.

Be Sociable, Share!

Comments are closed.