# Ability to have users add/edit/remove form fields dynamically?

**URL:** <https://forum.djangoproject.com/t/ability-to-have-users-add-edit-remove-form-fields-dynamically/9121>\
**Category:** Using Django\
**Created:** [August 6, 2021, 7:28pm UTC](https://forum.djangoproject.com/t/ability-to-have-users-add-edit-remove-form-fields-dynamically/9121 "2021-08-06T19:28:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![masterj\_02](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@masterj\_02](https://forum.djangoproject.com/u/masterj_02)\
**Post date:** [August 6, 2021, 7:28pm UTC](https://forum.djangoproject.com/t/ability-to-have-users-add-edit-remove-form-fields-dynamically/9121/1 "2021-08-06T19:28:58Z")

</div>

Hi everyone, I am working on a project that requires a base form + template for every user, based off of a simple model as such…

```auto
class FloorPlan(models.Model):
    user = models.ForeignKey(account)
    stories = models.IntegerField()
    bathrooms = models.IntegerField()
    sqft = models.IntegerField()

```

I know that JS will be needed to make this dynamic.

So every user will have a base form and view, which displays just those 3 fields. Now I also want this form to be customizable in a sense to let the user add any extra fields, or also remove fields that are not used. Maybe they add backyard info, pool info, etc.

I came across this app,

> **[GitHub - askvortsov1/dynamic-django-forms: A simple, reusable Django app that...](https://github.com/askvortsov1/dynamic-django-forms)**
>
> A simple, reusable Django app that allows you to build (and respond to) dynamic forms. Perfect for surveys, position applications, etc. - GitHub - askvortsov1/dynamic-django-forms: A simple, reusab...

but doesn’t seem to fit what I need.

I was thinking of adding an extra field called `extra_field=models.ForeignKey(ExtraField)` in the `FloorPlan` model, and make it a m2m, and in the `ExtraField` model just store the new fields the user wants to create. But design wise, dont think this would be best to let every user flood the DB?

I’ve been looking around to find maybe a JS library too.

Really just looking for some advice if anyone has created something similar, just looking for some pointers in the right direction.

TY in advance!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 6, 2021, 7:46pm UTC](https://forum.djangoproject.com/t/ability-to-have-users-add-edit-remove-form-fields-dynamically/9121/2 "2021-08-06T19:46:28Z")

</div>

The pattern isn’t a many-to-many - there’s no identified need here to have people share “extra data”. But there’s a fairly common pattern called the [“Entity-Attribute-Value”](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model) model that is about the closest fit to what you describe

e.g:

```auto
class Details(...):
    house = ForeignKey('FloorPlan', ...)
    attribute = CharField(...)
    value = CharField(...)

```

How detailed you make this is really only limited by your desire to enhance and add features, but you can really make this more sophisticated than presented here.  
(For example, one extension I’ve seen used is that the “value” column becomes a JSON object, and so you group multiple related data elements together into a particular attribute. In this case, you might define that an attribute named “room size” _must_ contain the length and width of the room. That attribute itself may be optional with any particular room, but _if_ it exists, you require both values be supplied.)
