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 8491395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:24:39+00:00 2026-06-10T22:24:39+00:00

Im trying to come up with a basic CRUD, nested resource implementation, with the

  • 0

Im trying to come up with a basic CRUD, nested resource implementation, with the following urls:

I cant figure out how to pass a default argument (the content type id, in my case) to the view. Below is what Ive used. Any pointers to accomplish this, or if this is total crap, any better way to accomplish this?

urlpatterns = patterns('',
   url (
       regex = '^/?$',
       view =  ParentResourceListView.as_view(),
       name = 'parent_resource_list'
   ),

   url (
       regex = r'^(?P<pk>\d+)/$',
       view =  ParentResourceDetailView.as_view(),
       name = 'parent_resource_detail'
   ),
   url (
       regex = r'^new/$',
       view =  ParentResourceCreateView.as_view(),
       name = 'parent_resource_create'
   ),

   url (
       regex = '^(?P<pk>\d+)/delete/$',
       view =  ParentResourceDeleteView.as_view(),
       name = 'parent_resource_delete'
   ),
   url (
       regex = '^(?P<pk>\d+)/edit/$',
       view =  ParentResourceUpdateView.as_view(),
       name = 'parent_resource_update'
   ),
)


urlpatterns += patterns('',
                   url (
    regex = r'^(?P<object_id>\d+)/child_resources$',
    view =  ChildResourceListView.as_view(),
    name = 'parent_resource_child_resource_list',
    kwargs = {
        "content_type",
        ContentType.objects.get_for_model(ParentResource).id
        }
    ),
                   url (
    regex = r'^(?P<object_id>\d+)/child_resources/(?P<pk>\d+)/$',
    view =  ChildResourceDetailView.as_view(),
    name = 'parent_resource_child_resource_detail',
    kwargs = {
        "content_type",
        ContentType.objects.get_for_model(ParentResource).id
        }
    ),
                   url (
    regex = r'^(?P<object_id>\d+)/child_resources/new/$',
    view =  ChildResourceCreateView.as_view(),
    name = 'parent_resource_child_resource_create',
    kwargs={
        "content_type",
        ContentType.objects.get_for_model(ParentResource).id
        }
    ),

                   url (
    regex = '^(?P<object_id>\d+)/child_resource/(?P<pk>\d+)/delete/$',
    view =  ChildResourceDeleteView.as_view(),
    name = 'parent_resource_child_resource_delete',
    kwargs={
        "content_type",
        ContentType.objects.get_for_model(ParentResource).id
        }
    ),
                   url (
    regex = '^(?P<object_id>\d+)/child_resource/(?P<pk>\d+)/edit/$',
    view =  ChildResourceUpdateView.as_view(),
    name = 'parent_resource_child_resource_update',
    kwargs={
        "content_type",
        ContentType.objects.get_for_model(ParentResource).id
        }
    ),
                   )

Edit:

The views Im using are inspired by this post

class ParentResourceMixin(object):
    model = ParentResource
    def get_success_url(self):
        return reverse('parent_resource_list')
    def get_queryset(self):
        return ParentResource.objects.all()


class ParentResourceListView(ParentResourceMixin, ListView):
    pass


class ParentResourceDetailView(ParentResourceMixin, DetailView):
    pass


class ParentResourceCreateView(ParentResourceMixin, CreateView):
    pass


class ParentResourceDeleteView(ParentResourceMixin, DeleteView):
    pass


class ParentResourceUpdateView(ParentResourceMixin, UpdateView):
    pass

Edit (solution based on jpic’s answer):

The child resource views are:

class ChildResourceMixin(object):

    content_type = None

    model = ChildResource
    def get_success_url(self):
        return reverse('child_resource_list')
    def get_queryset(self):
        return ChildResource.objects.all()


class ChildResourceListView(ChildResourceMixin, ListView):
    pass


class ChildResourceDetailView(ChildResourceMixin, DetailView):
    pass


class ChildResourceCreateView(ChildResourceMixin, CreateView):
    pass


class ChildResourceDeleteView(ChildResourceMixin, DeleteView):
    pass


class ChildResourceUpdateView(ChildResourceMixin, UpdateView):
    pass
  • 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-06-10T22:24:40+00:00Added an answer on June 10, 2026 at 10:24 pm

    CBV docs:

    If you’re only changing a few simple attributes on a class-based view, you can simply pass them into the as_view method call itself

    ParentResourceListView.as_view(
        content_type=ContentType.objects.get_for_model(ParentResource).id)
    

    For this to work, you should define a class attribute, ie.

    class ChildResourceMixin(object):
        content_type = None
    

    This will enable argument passing from as_view().

    I like what your code looks like, it looks simple and flexible.

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

Sidebar

Related Questions

I'm trying to come up with an algorithm that will do the following: If
I am trying to figure out the use of Maven and I got many
I've been trying to figure out the best way to model this entity, and
Trying to come up with a basic way to display code in a way
I'm trying to come up with a function that lets me pass in any
I am trying to figure out this map/reduce system in mongoDB. I have the
im trying to come up with a design for a wrapper for use when
I'm trying to come up with a good naming convention for boolean variables that
I am trying to come up with a query in MS Acess to compare
I'm trying to come up with a way combine two arrays that have different

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.