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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:02:12+00:00 2026-05-13T17:02:12+00:00

I am about to start a large Django project at work. And the key

  • 0

I am about to start a large Django project at work. And the key features are form handling. There is going to be a lot of forms that the users of the app is going to use. And one requirement is that it should be possible to edit the forms in the admin interface of the application.

That is, it is not a requirement to add/delete form fields. But it should be possible to edit form field attributes. E.g change which fields which is required and such.

Anybody have any good solutions on how to do this. I’m thinking that I might have to subclass the fields I want to be dynamic and do something there. I guess that all the models fields have to have "blank=True/null=True" and some how add some meta information in a separate model(?) about the model which declares which fields are required. And then use that information when forms is displayed and validated.

Before I start off doing this I would really like some input in how to design such a solution, anybody got ideas on how it should be done?


After more research, I’ve learned that you could do a lot with factory functions that would return the form with the given attributes set. So it looks like the problem is not that hard do solve.

I would make a function that returns a form with the right attributes/fields set. But the part that I haven’t found a good solution for is how to manage this in the admin interface. I am thinking that I would make a db.Model that stores information about another models fields. Where I can set which is required and such.

And then in the function that returns the form, go trough that model and return a form with the right attributes. But how to make that model (which should mirror another model’s fields) in a good way?

  • 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-13T17:02:12+00:00Added an answer on May 13, 2026 at 5:02 pm

    You should use certain models for this. For every form that might be customised this way, a new database entry must be created. I guess, it should look like this:

    class FormSettings(Model):
      form = CharField(..)
    
    class FormAttrib(Model):
      form_settings = ForeignKey(FormSettings)
      field = CharField(..)
      attrib_name=CharField(..)
      attrib_value=CharField(..)
    

    In FormSettings.form you should store some address of form, like say . and when form is built (in init), it should look for an entry in db and use attribs, that were described for it.

    You can make it create db entries easily, if you use own metaclass for your forms and make it register in the database (create proper FormSettings entry), when a class is created. It will be done once when the process is started, which shouldn’t be that bad.

    I hope it helps a little. If you have further questions, I’ll be happy to help 🙂 I like those non standard appliances of django 🙂 This is where all the fun begins 🙂

    EDIT:

    OK, let’s say, that you want to you have app food and form FavouriteFoodForm with food_name field. You store in the database in formsettings table as food.FavouriteFoodForm and add one attribute setting: field=’food_name’, attrib_name=’required’, attribute_value=’True’ (it’s not perfect, but still it’s not that bad’).

    No in FavouriteFoddForm you look for the settings in database, so you do:

    settings = FormSettings.objects.get(form=app_name + self.__class__.name)
    

    and you iterate over settings

    for setting in settings.formattrib_set():
    

    and here you simple call exec and set proper attribute:

    exec("getattr(self, settings.field)[attrib_name] = %s" % attrib_value)
    

    This should set attributes to required=True.

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

Sidebar

Related Questions

I'm about to start a project that will record and edit audio files, and
I am about to start on a journey writing a windows forms application that
I'm about to start on a large Qt application, which is made up of
I'm about to start a project for a customer who wants CMS-like functionality. They
I am about to start a new project and would like to document its
I am about to start a project for a potentially heavily accessed ASPNET MVC
I am about to start a web project and have been working almost exclusively
I'm about to start a fairly Ajax heavy feature in my company's application. What
I'm about to start testing an intranet web application. Specifically, I've to determine the
I'm about to start (with fellow programmers) a programming & algorithms club in my

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.