I'm working through the tutorial, applying its lessons to my own
database.  So for example where it covers writing a detail view for the
Poll model, I think really I'm going to want a detail view for each of
the models in my database, and they're all going to be the same except
for the name of the model and the actual stuff that gets output, which
will be controlled by the model-specific template.

So I come up with a url mapping that looks like this:

urlpatterns = patterns('kmt.crossword.views',
    (r'^(?P<model_name>\w+)/(?P<id>\d+)/$', 'detail'),
)

and my views.py is very simple:

from django.db.models import get_model
from django.shortcuts import render_to_response, get_object_or_404

def detail(request, model_name, id):
    model = get_model('crossword', model_name)
    instance = get_object_or_404(model, pk=id)
    return render_to_response(model_name + '_detail.html', {'instance':
instance})

This works nicely, but I have a few niggling questions.  First I found
that useful get_model function not in the documentation, but by looking
around in the Django code.  Is this something I should be using, or is
it really only intended for Django internal use?  If it's not something
I should be using, where should I be looking to figure out how to
accomplish the kind of thing it does for me?

Second, it seems a bit inelegant to hardcode my own app name
('crossword') here.  Seems like there should be some way for my
kmt.crossword.views code to figure out that its own app name is
'crossword', but how to do that is eluding me.  I'm not quite sure I'm
going to stick with that name so I'd like to minimize the places I have
it hard-coded.

(Finally I know I am ignoring some error cases at the momemt, like if a
url with a non-existant model name comes in.  I know I have to deal
with that but right now I'm concentrating on the model names that do
exist.)

Thanks for any feedback -- I'm a complete Python and Django novice so
welcome any and all suggestions as to how I should be approaching this
in the proper manner.

Karen


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to