Skip to content

Entangled field having list of data #19

@dineshh912

Description

@dineshh912

Entangled Form is working great so far, consider below models.py

models.py

class Customer(models.Model):
    name = forms.CharField(max_length=255)
    address = forms.JsonField()

The out put i am looking forward to is

{'name ': 'john doe', 'address': [ {'city': 'zxc', 'zipcode': 'zxc'}, {'city': 'zxc', 'zipcode': 'zxc'} ] }

Is there a way to get above output using entangled forms?
I tried to combine entangled forms with formset_factory()

below is output i am getting when combine with formset_factory()

[{'name ': 'john doe', 'address': {'city': 'zxc', 'zipcode': 'zxc'} }, {'name ': 'john doe', 'address': {'city': 'zxc', 'zipcode': 'zxc'} }, {'name ': 'john doe', 'address': {'city': 'zxc', 'zipcode': 'zxc'} }]

forms.py

class testForm(EntangledModelForm):
    city = forms.CharField(max_length=255, required=True)
    zipcode = forms.CharField(max_length=34, required=True)

    class Meta:
        model = Customer
        entangled_fields = {"address": ['city', 'zipcode'] }
        untangled_fields = ['name']


testFormSet = formset_factory(testForm, extra=1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions