Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 353843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:52:05+00:00 2026-05-12T11:52:05+00:00

Can the object value be looked up and passed to the generic view? Would

  • 0

Can the object value be looked up and passed to the generic view? Would the generic views need to be moved to views.py in order to support the object lookup?

urls.py

urlpatterns = patterns('myapp.views',
        url(r'^mymodel/create/$', view='mymodel_create',  name='mymodel_create'),
)

urlpatterns += patterns('django.views.generic',
        url(r'^(?P<model>\w+)/create/$','create_update.create_object', name='object_create'),
        url(r'^(?P<model>\w+)/(?P<id>\d+)/update/$', 'create_update.update_object', name='object_update' ),
        url(r'^(?P<model>\w+)/(?P<id>\d+)/delete/$', 'create_update.delete_object', name='object_delete'),        url(r'^(?P<model>\w+)/(?P<object_id>\d+)/$', 'list_detail.object_detail',  name='object_detail'),
        url(r'^(?P<model>\w+)/$','list_detail.object_list', name='object_list'),'
)

Example URL’s:

http://localhost/myapp/thing/create
http://localhost/myapp/thing/1
http://localhost/myapp/thing/1/update
http://localhost/myapp/thing/1/delete

I’d like to use (?P\w+) to find the corresponding Model, ‘Thing’, but when this code is executed, the following error occurs: object_list() got an unexpected keyword argument ‘model’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:52:06+00:00Added an answer on May 12, 2026 at 11:52 am

    Yes, you can do this, and I’ve done it. The Django generic views don’t support it directly. You need to wrap the generic view with your own view that looks up the model and constructs the queryset. Here’s an example (showing only the detail view, you can do the others similarly). I’ve changed your named patterns in the URLconf to use “model” instead of “object”, which is clearer naming:

    in urls.py:

    url(r'^(?P<model>\w+)/(?P<object_id>\d+)/$', 'my_app.views.my_object_detail',  name='object_detail'),
    

    in my_app/views.py

    from django.views.generic.list_detail import object_detail
    from django.db.models.loading import get_model
    from django.http import Http404
    
    def get_model_or_404(app, model):
        model = get_model(app, model)
        if model is None:
            raise Http404
        return model
    
    def my_object_detail(request, model, object_id):
        model_class = get_model_or_404('my_app', model)
        queryset = model_class.objects.all()
        return object_detail(request, queryset, object_id=object_id)
    

    If you’re clever and want to keep things as DRY as possible, you could create a single wrapper that accepts the generic view function to call as one of its arguments, rather than having a wrapper for create, a wrapper for update, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can an object be loaded via Hibernate based on a field value of
I'm looking for a key/value pair object that I can include in a web
How can dynamic Key-value pairs of objects be stored in app.config in using the
Why I can use Object Initializers in Visual Studio 2008 Windows projects, etc targeted
What is the maximum length in characters a CString object can hold?
Given an SQLConnection object how can you get a schema for a single table?
I have an object I can serialize to XML without a problem. However when
I have an object that can build itself from an XML string, and write
I am aware that you can lock an object in c# using lock but
I am wondering how I can define an object in C whose reference will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.