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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:45:37+00:00 2026-05-16T18:45:37+00:00

I want to make some functions that are re-usable by any model so that

  • 0

I want to make some functions that are re-usable by any model so that I can specify the appname and model in string format and then use this to import that model and make calls to it such as creating database fields, updating, deleting, etc…

I had thought I could do this using contenttypes in Django but am trying this, as below and am getting the error message “‘ContentType’ object is not callable”:

    from django.contrib.contenttypes.models import ContentType
    instancemodelname = ContentType.objects.get(app_label="myappname", model="mymodelname")

    b = instancemodelname(account_username='testtestest')
    b.save()
    >>>>'ContentType' object is not callable

I would appreciate any advice on the proper way to do this, thanks

  • 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-16T18:45:37+00:00Added an answer on May 16, 2026 at 6:45 pm

    The following code will work:

    instancemodelname = ContentType.objects.get(app_label="myappname", model="mymodelname")
    b = instancemodelname.model_class()(account_username='testtestest')
    b.save()
    

    That said I am not entirely convinced that contenttypes is the best way to achieve what you want.

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

Sidebar

Related Questions

I want to make a program that will read some number in string format
i got some php classes and functions that i want to make it avliable
Specifically, I want to create a backup of a list, then make some changes
I have some functions that read and modify files. In order to make the
I have some functions that can be grouped together, but don't belong to some
I want to be able to test some inner functions that I have without
I want to make some tests on my modules. Unfortunately, some functions in these
I want to make a page that displays some data from a DB, so
i want make a app with xul but some functions and logic in a
I'm wondering if I can define some functions in a header file and then

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.