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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:21:00+00:00 2026-05-23T12:21:00+00:00

I have three functions which I need in every Django Model: def __unicode__(self): return

  • 0

I have three functions which I need in every Django Model:

def __unicode__(self):
            return self.MODELNAME_name

def get_absolute_url(self):
            return "/MODELNAME/list/" 

def get_fields(self):
            return [(field, field.value_to_string(self)) for field in MODELNAME._meta.fields]

The only thing different is the MODELNAME

How can I use inheritance so that I use three functions in one class and other inherit from it?

  • 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-23T12:21:01+00:00Added an answer on May 23, 2026 at 12:21 pm

    You could use multiple inheritance:

    class CommonFunctions(object):
        def __unicode__(self):
            return self.MODELNAME_name
        def get_absolute_url(self):
            return "/MODELNAME/list/" 
        def get_fields(self):
            return [(field, field.value_to_string(self)) for field in MODELNAME._meta.fields]
    
    class ZeModel(models.Model, CommonFunctions):
        [...]
    
    x = ZeModel()
    x.get_absolute_url()
    

    (Make sure you replace MODELNAME with self.__class__.__name__)

    I did not test this, but it should work.

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

Sidebar

Related Questions

ANSWERED! IT WAS A TYPO OMG. Always check EVERY CHARACTER I have three controllers,
I have a function in which I call getaddrinfo() to get an sockaddr* which
I have a class structure which represents (internally) the data I wish to output
I have a mission critical Perl-CGI server-side application that I need to extend or
I have a database containing three tables: practices - 8 fields patients - 47
So if I have two data types which are mostly the same, I can
I have created an app which includes popups of different dialogs. Here is my
Novice question here. I'm working on finding every single combination of various string elements,
i am trying to find out a way in which i can write out

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.