django-entangled
django-entangled copied to clipboard
Entangled field having list of data
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)
Must necessary. I basically need this but can not explain to the maintainer https://github.com/jrief/django-entangled/issues/9
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.
Will give a try to django-formset, thanks
@dineshh912 Any update?
The right in this case would not be better to use modelformset-factory?