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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:30:30+00:00 2026-05-29T12:30:30+00:00

What is the best way to write a class based view that both shows

  • 0

What is the best way to write a class based view that both shows a date-based object and a form? The use case is a site index page view that both displays today’s object and has a contact form.

At first I thought of using TodayArchiveView and ContactFormView as mixins for my site index page view. However, TodayArchiveView inherits from BaseDateListView, and ContactFormView inherits from ProcessFormView. Both ProcessFormView and BaseDateListView implement get() and ultimately call render_to_response with very different data, so I’m thinking this won’t work because even if I could call both through super, which would be returned? (I’m not even sure my thinking on this is correct; I’m still wrapping my head around multi-inheritance.)

Then I thought of writing my own get() that combines the functionality of the two gets, since their functionality doesn’t collide, as far as I can tell. So that ended up looking like:

def get(self, request, *args, **kwargs):
    form_class = self.get_form_class()
    form = self.get_form(form_class)

    self.date_list, self.object_list, extra_context = self.get_dated_items()
    context = self.get_context_data(form=form, object_list=self.object_list,
        date_list=self.date_list)
    context.update(extra_context)
    return self.render_to_response(context)

Is this the right approach?

As a larger question, how do you know which mixins can be used with each other? I had to go to the django source to realize that both classes were implementing get().

  • 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-29T12:30:31+00:00Added an answer on May 29, 2026 at 12:30 pm

    Is your form related to the object or not? From the description it seems it isn’t, and I’m guessing that your contact form is in some kind of a sidebar or a similar site-wide (or at least a section-wide) element.

    If that is correct I wouldn’t include the form in the view at all; instead, I would use a tag or an include or a similar method to place a separately-defined template.

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

Sidebar

Related Questions

What's the best way to write a LINQ query that inserts a record and
What is the best way to write a function (or something DSLish) that will
What's the most idiomatic way to write a class definition? There's no way that
What is the best way to write data to the text console at arbitrary
What is the best way to write bytes in the middle of a file
What's the best way to write a supybot plugin in ruby? Or other language
What's the best way to write an application in order to get it working
What would be the best way to write log statements to a file or
What would be the best way to write a generic copy constructor function for
Following on from this question what would be the best way to write a

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.