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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:39:46+00:00 2026-05-11T10:39:46+00:00

How add custom field dynamicly? I’m trying that, but the field won’t insert into

  • 0

How add custom field dynamicly? I’m trying that, but the field won’t insert into database when I sync db:

#It use as register(MyModel) def register(model, attr='my_attr'):      if model in registry:         raise AlreadyRegistered(             _('The model %s has already been registered.') % model.__name__)      registry.append(model)     setattr(model, attr, MyField())      MyField().contribute_to_class(model, attr)   #MyField.contribute_to_class def contribute_to_class(self, cls, name):      super(MyField, self).contribute_to_class(cls, name)       setattr(cls, self.name, self)      cls.add_to_class('%s_manager' %  name, MyDescriptor())       signals.post_save.connect(self._save, cls, True) 
  • 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. 2026-05-11T10:39:46+00:00Added an answer on May 11, 2026 at 10:39 am

    You probably cannot do that without hacking into Django’s internals. The syncdb command inspects the meta object for each model to get a list of fields to create, which is created on class construction time via the metaclass of the django.db.models.Model base class:

    class MyModel(models.Model):     my_filed = models.CharField(...)  # Here, class construction is complete and your class has a _meta member. # If you want, you can check it out in the interactive shell. meta = MyModel._meta 

    After the class construction is complete, e.g. after the DEDENT following the class statement, the meta object is fixed (not affected by modifying the model class) and you will have to hack the meta (which is of course possible) in order to add dynamic fields. But since you are messing with internal objects here, it could render your app incompatible with future releases of Django.

    The remaining question is: Why would you want to do that? Since database tables are usually only created once when deploying your app, models are kind of ‘static’.

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

Sidebar

Related Questions

I'm trying to add a custom property which is a guid, but it gives
I'm trying to add custom validation to a dynamically created control. Can I use
I am trying to handle add a custom field to a user profile using
I am trying to add some custom build steps to my headless build process
I'm trying to add a custom font as a resource in my application. I
How can I add custom properties into control objects in ExtJs. For example :
I used hook_nodeapi to add my custom field to a type of node $node->content['my_new_field']
Is it possible to add custom command-line arguments to an Eclipse .app folder? In
I would like to add custom tooltips to emacs. More specifically, whenever I hover
As I'm working to add custom printing to my application, I've settled on using

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.