Thanks for replying Daniel. I wanted to know if I can use generic views for web application form objects. I would like to use them to avoid duplication on html pages.
On Sep 25, 1:20 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Sep 25, 8:51 pm, Karthik Krishnan <[EMAIL PROTECTED]> wrote: > > > > > I know this may be a stupid question but please bear with me. Here is > > my problem > > > In views.py I have a multiple methods, where each method is mapped to > > a unique model. There may be multiple methods mapped to the same > > model. But no method in views.py is mapped to multiple models. > > > For a GET/POST request, we have mapped a form object to the request > > method. To display the form on the HTML page, we have to do > > {{form.as_p}} or {{form.as_ul} and so on.. But we have to display it > > differently with div tags using css files. > > > If I have to do it individually, then I would have to this as follows > > > <div class = "">Name</div> <div class= "">{{form.name}</div> and so > > on... > > > Question 1 : Is there a way we can do it? > > > The reason I am asking this is because we have 20 html forms and we > > would like to make it as automated as possible by invoking this > > method. What I am hoping for is something like this. Ideally this is > > what I hope to do. > > > In my urls. py I could define the model > > > ulr.py > > > urlpatterns = patterns('', > > (r'^login/$', views.object_list, {'model': models.User}), > > (r'^customers/([A-Za-z0-9].*/$', views.object_list, {'model': > > models.Customer}), > > ) > > > In My views.py, I could return the same key for any number of models, > > only my template would change > > > def login(request, model): > > user = model.objects.filter(username = 'abcedf') > > return render_to_response('success.html', {'form', user}) > > > def getCustomer(request, customer_name model): > > customer = model.objects.filter(name = customer_name) > > return render_to_response('success.html', {'form', customer}) > > > In my success html page > > > I would display them as > > > {{form.as_div}} > > > Any help/suggestions would be more than welcome. > > I'm not entirely sure I follow, but it sounds like Django's generic > views would do the trick. > Seehttp://docs.djangoproject.com/en/dev/ref/generic-views- > specifically the section on create/update views. That does the view/ > form part for you, allowing you simply to define the URL in your > urls.py and give it a template. Is that what you're after? > > -- > DR. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---