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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:07:22+00:00 2026-05-18T01:07:22+00:00

Django (and database) newbie here. I’m trying to figure out a way to enable

  • 0

Django (and database) newbie here.

I’m trying to figure out a way to enable the creation of n custom text fields for a table (let’s call it Book) using the admin interface. I would like a way for the user to define new text fields through the admin interface (instead of defining fields like CustomField1, CustomField2, etc, through a model followed by running manage.py syncdb).

Ultimately, I would want to create a separate table called CustomFields. The django admin user (who is not a programmer), would go and enter the custom text fields in this table (e.g. pubdate, isbn, country). Then, when doing data entry for a Book, they would hit “+” for every custom field they wanted, have them available in a dropdown, and add accompanying text for the custom field. The text entered for each field is specific to the parent Book.

Any suggestions? I have a feeling there’s a simple solution that I’m somehow not grasping here.

  • 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-18T01:07:23+00:00Added an answer on May 18, 2026 at 1:07 am

    Where you might run into problems is because Django will not recreate tables or columns based on changing model declarations. This means you’re unable to add fields to a table at run-time without running the generated sql on your database manually. What you’ll need, instead, is a way of defining custom fields, and linking them to your model.

    What I’d suggest is the following:

    class CustomField(models.Model):
        name = models.CharField(max_length=32)
    
    class Book(models.Model):
        ... fields
    
    class CustomValue(models.Model):
        field = models.ForeignKey(CustomField)
        value = models.CharField(max_length=255)
        book = models.ForeignKey(Book)
    

    The validation on the above is fairly non-existant, and this doesn’t allow you to define required custom fields for each model, but you should be able to come up with that part if you need it later on.

    # taken and modified from django online tutorial
    class CustomValueInline(admin.StackedInline):
        model = CustomValue
        extra = 3
    
    class BookAdmin(admin.ModelAdmin):
        fieldsets = [
           # your fields in here
        ]
        inlines = [CustomValueInline]
    
    admin.site.register(Book, BookAdmin)
    

    This will allow users to select up to 3 custom fields and values directly, with the option to add more if they wish.

    Edit: Changed the answer to reflect further information in comments.

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

Sidebar

Related Questions

Is there an easy way to reset a django database (i.e. drop all data/tables,
Im trying to render a django template from a database outside of djangos normal
PostgreSQL / Django / newbie here. I've got a bunch of JSON data with
i'm a newbie django developer, trying to build demo pages for my cpp and
I'm trying to integrate a legacy database in Django. I'm running into problems with
I'm trying to have a purely in-memory SQLite database in Django, and I think
What's the best way to move large dataset from one django database to another?
I am trying to connect to a remote mysql database using django. The documentation
I'm a Django newbie who needs your help Have this database model: class Record(models.Model):
I'm a Django newbie and I wonder if there is a more efficient way

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.