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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:30:30+00:00 2026-05-26T08:30:30+00:00

I would like to mix a field into an existing model which I would

  • 0

I would like to mix a field into an existing model which I would rather not edit (it comes from a third party project and I would rather leave the project untouched). I have created a simple example which illustrates what I am trying but unable to do:

In an empty Django project I have created apps app1 and app2 (they are in that order in settings). They look like the following:

app1.models.py:

from django.db import models
from app2.models import BlogPost

class BlogPostExtend(models.Model):
    custom_field_name = models.CharField(max_length=200)

    class Meta:
        abstract = True

BlogPost.__bases__ = (BlogPostExtend,)+BlogPost.__bases__ # this prevents MRO error

app2.models.py:

from django.db import models

class BlogPost(models.Model):
    field_name = models.CharField(max_length=100)

Unfortunately this does not result in custom_field_name being created in the database when I syncdb, although at the command line if I type BlogPost.custom_field_name it does recognize it as a CharField. I know that in this simple case I could have BlogPost inherit from BlogPostExtend, but in the real use case I cannot edit BlogPost.

This is a very simplified example but it illustrates what I am trying to do.

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-26T08:30:31+00:00Added an answer on May 26, 2026 at 8:30 am

    Mixins work great with adding attributes and methods, but not fields.

    In app1.models.py, do this instead:

    from django.db import models
    from app2.models import BlogPost
    
    custom_field_name = models.CharField(max_length=200)
    custom_field_name.contribute_to_class(BlogPost, "custom_field_name")
    

    I think also the app1 app should come after app2 in INSTALLED_APPS for this to work.

    Here is an explanation on contribute_to_class

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

Sidebar

Related Questions

I have two strings and I would like to mix the characters from each
I would like to use a mix-in class to add properties to a model.
Can you mix .net languages within a single project? So pre-compiled, I would like
Would like to make anapplication in Java that will not automatically parse parameters used
I have a .NET application (mix of C# and VB.NET) where I would like
I would like to implement google analitycs on a website that's a mix of
I have an existing web service that returns XML responses and I would like
I would like to mix MP3 files with Delphi 2010. Is this possible? Does
I would like to do something like this (mix of sql with pseudocode): let's
I would like to know if it's a good idea to mix Moustache or

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.