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

  • SEARCH
  • Home
  • 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 4607316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:41:09+00:00 2026-05-22T00:41:09+00:00

What I’m trying to do is Django boilerplate for functional views. Any help here

  • 0

What I’m trying to do is Django boilerplate for functional views. Any help here is very much appreciated, as the docs show examples for the template view and list view, but I’ve found very little for the model-based generic views. Am I missing an example in the docs?

I have a model that represents an entry in a calendar. There’s a foreign key to another object (not a user) that owns the entry. What I want to do is simply to create the entry, ensuring that the entry’s foreign key is properly set and then return the user to the appropriate calendar page.

I don’t know, though, how class-based generic views receive their URL arguments and I’m not clear on how to set the success_url so that it reuses the id that was originally passed to the creation URL. Again, thank you in advance for your help.

What I’m asking, essentially, is, what is the class-based generic view equivalent of the following:

def create_course_entry(request, class_id):
'''Creates a general calendar entry.'''
if request.method == 'POST':
    form = CourseEntryForm(request.POST)
    if form.is_valid():
        new_entry = form.save(commit=False)
        new_entry.course = Class.objects.get(pk=class_id)
        new_entry.full_clean()
        new_entry.save()
        return HttpResponseRedirect('/class/%s/calendar/' % class_id)
else:
    form = CourseEntryForm()

return render_to_response('classes/course_entry_create.html',
        { 'class_id': class_id, 'form': form, },
        context_instance=RequestContext(request))
  • 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-22T00:41:10+00:00Added an answer on May 22, 2026 at 12:41 am

    You could subclass the edit.CreateView generic view, set the class/course in the dispatch() method, and save this by overriding the form_valid() method:

    from django.http import HttpResponseRedirect
    from django.shortcuts import get_object_or_404
    from django.views.generic.edit import CreateView
    
    
    class CourseEntryCreateView(CreateView):
        form_class = CourseEntryForm
        model = CourseEntry
    
        def dispatch(self, *args, **kwargs):
            self.course = get_object_or_404(Class, pk=kwargs['class_id'])
            return super(CourseEntryCreateView, self).dispatch(*args, **kwargs)
    
        def form_valid(self, form):
            self.object = form.save(commit=False)
            self.object.course = self.course
            self.object.save()
            return HttpResponseRedirect(self.get_success_url())
    

    If you’re not customising the CourseEntryForm ModelForm, then you can leave out the form_class property.

    Unfortunately, it is not possible to call super() in the form_valid() method – due to the way it has been written would mean the object would be saved again.

    If you need the Class (course?) instance in the template context, then you can add this in the get_context_data() method:

        def get_context_data(self, *args, **kwargs):
            context_data = super(CourseEntryCreateView, self).get_context_data(
                *args, **kwargs)
            context_data.update({'course': self.course})
            return context_data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.