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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:31+00:00 2026-06-15T19:12:31+00:00

So I have this class which is an abstract parent class to a bunch

  • 0

So I have this class which is an abstract parent class to a bunch of other classes, let’s call it ActivityModel (representing some sort of latest activity/or change done to that object) and I want to override the save method to take another argument every time the object is saved so I define it as follows.

class ActivityModel(models.Model):
    last_updated = models.DateTimeField(auto_now=True)
    updater = models.ForeignKey(UserProfile)
    change = models.CharField(max_length=255)

    def save(self, updater, change, *args, **kwargs):
        self.updater = updater
        self.change = change
        super(ActivityModel, self).save(*args, **kwargs)

    class Meta:
        abstract = True

But now all the models that I make inherit this class can’t use ModelForms because I’ve changed the save method to require this second field (the UserProfile corresponding to the authenticated user which must be supplied every time it is saved) so I was wondering if it is possible for me to subclass the ModelForm class to override it’s save method so that it will call the new ParentModel.save method and fill in the currently logged in user that has been supplied to it. I figure I can just supply the UserProfile on the forms init, but the big question I have is whether it is possible to subclass the ModelForm class and create like a ParentModelForm class which can then be subclassed for each of ParentModel’s child classes. Is this possible and if so, how would I go about doing it?

All help is very much appreciated! Thanks for your time!

  • 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-15T19:12:32+00:00Added an answer on June 15, 2026 at 7:12 pm

    ModelForm is also a python class with a similar behavior as the other classes.

    #Inherits from ModelForm class
    class ParentModelForm(forms.ModelForm):
    ...
    ...
       def save(self, *args, **kwargs):
         ...
         ...
    #Inherits from ParentModelForm
    class ChildModelForm(ParentModelForm):
    ..
    ..
      #You would have to override the Meta class
      class Meta:
          model = Child
      def save(self, *args, **kwargs):
           #Calling the parent model form save method
           super(ChildModelForm, self).save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this: abstract class Parent { protected function foobar($data)
I have this parent abstract class which defines an Apache logger static object. Something
I have an abstract parent class which child classes that inherit from it. I
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I have an abstract parent class Item , from which different types of items
I have a parent class, like this: public abstract class Business<T> : IBusiness<T> where
I have a similar structure like this: Parent class abstract class parentActions extends sfActions
I have a parent class with one important abstract procedure which I am overloading
I have a abstract class called Customer which has some attributes shared amongst all
Let us assume we have the two following classes: abstract case class MyParent(param: Int)

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.