django-entangled icon indicating copy to clipboard operation
django-entangled copied to clipboard

Entangled field having list of data

Open dineshh912 opened this issue 2 years ago • 10 comments

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)

dineshh912 avatar Apr 12 '22 15:04 dineshh912

Must necessary. I basically need this but can not explain to the maintainer https://github.com/jrief/django-entangled/issues/9

nikolas-dev avatar Apr 28 '22 16:04 nikolas-dev

I never tested django-entangled with formset_factory.

Something you can try is my other project django-formset. This offers the same functionality as formset_factory, but IMHO better. The form returns JSON and it should work together with django-entangled. I have to add some more tests though.

jrief avatar Apr 28 '22 19:04 jrief

Will give a try to django-formset, thanks

dineshh912 avatar Apr 29 '22 08:04 dineshh912

@dineshh912 Any update?

nikolas-dev avatar Jul 14 '22 20:07 nikolas-dev

The right in this case would not be better to use modelformset-factory?

CleitonDeLima avatar Sep 30 '22 15:09 CleitonDeLima