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

The Archive Base Latest Questions

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

Instead of dynamically altering a models file by adding fields, very bad i’ve been

  • 0

Instead of dynamically altering a models file by adding fields, very bad i’ve been told, i’m suppose to maintain a type of flexibility by having variable field list names(i think).

Thus, when an attribute is added to the database, this attribute can be accessed without the models file being altered.

I cant figure out how to create variable field list names in my models class though.
I’m having trouble sifting through reading materials to find a solution to my problem, and trial and era is 15hrs and counting.

Could some one point me in the right direction.

New Edit

Heres what im trying to achieve.

When an attribute is added, i add it to the table like this.

    c = 'newattributename'

    conn = mdb.connect('localhost', 'jamie', '########', 'website')
    cursor = conn.cursor()
    cursor.execute("alter table mysite_weightsprofile add column %s integer not null; SET @rank=0; UPDATE mysite_weightsprofile SET %s = @rank:=@rank+1 order by %s DESC;" %  (c, c, a))
    cursor.close()
    conn.close()

Now, in my models class i have

class WeightsProfile(models.Model):
    1attributes = models.IntegerField()
    2attributes = models.IntegerField()
    3attributes = models.IntegerField()

class UserProfile(WeightsProfile):
    user = models.ForeignKey(User, unique=True)
    aattributes = models.CharField()
    battributes = models.CharField()
    cattributes = models.CharField()

Now all i want to do is get access to the new attribute that was added in the table but not added to in the models file.

Does sberry2A have the right answer. I hope it is, it seems the simplest.

  • 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-26T15:30:15+00:00Added an answer on May 26, 2026 at 3:30 pm

    I might not be following what you are asking, but assuming you have some model, like Person, which will start out having some defined fields, but may have several more added in the future…

    class Person(models.Model):
    
        fname = models.CharField(max_length=255)
        lname = models.CharField(max_length=255)
        age = models.IntegerField()
        # more fields to come
    

    Then you could use a PersonAttribute model…

    class PersonAttribute(models.Model):
    
        name = models.CharField(max_length=32)
        value = models.CharField(max_length=255)
    

    Then you could just add a ManyToMany relationship field to your Person…

        attributes = models.ManyToManyField(PersonAttribute)
    

    Or something similar.

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

Sidebar

Related Questions

i've didn't found some examples to create NSPopover dynamically instead using the Interface Builder.
I have a flowpanel that I'm dynamically adding usercontrols to. I want it to
How can I dynamically build a list of mappings - instead of: class UrlMappings
I'm trying to dynamically generate a csv file with some cells that will contain
I've been trying to think of a way to dynamically return property values for
is it possible to embed sources dynamically. instead of doing this [Embed(source = '../../../../assets/levels/test.xml')]
I would like to create a form dynamically instead of using the XAML to
I want to replace IP dynamically but somehwo sed is placing word $IP instead
I need at some point to increment dynamically a timestamp plsql variable. So, instead
...instead of using the Atom syndication format? Atom is a well-defined , general-purpose XML

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.