Comments (4)
Hi @flaudizio,
Are you talking about MultiForm?
You can use an a FormSet inside of a MultiForm. There is an example of using an inline formset inside of a MultiForm in the tests: https://github.com/fusionbox/django-betterforms/blob/master/tests/forms.py#L129-L146
Is that what you were thinking?
from django-betterforms.
Hi, thank's a lot.
One else thing, when I save in view I get this error:
can't set attribute
multiform.py in is_valid:
try:
cleaned_data = self.clean()
except ValidationError as e:
self.add_crossform_error(e)
else:
if cleaned_data is not None:
for key, data in cleaned_data.items():
self.forms[key].cleaned_data = data
...
return forms_valid and not self.crossform_errors
def non_field_errors(self):
form_errors = (
form.non_field_errors() for form in self.forms.values()
if hasattr(form, 'non_field_errors')
My forms.py
class ContactForm(ModelForm):
class Meta:
model = Contact
fields = ['name']
class PhoneForm(ModelForm):
class Meta:
model = Phone
fields = ['number']
PhoneInlineFormSet = inlineformset_factory(Contact, Phone,
fields=('number',), extra=3)
class ContactPhoneForm(MultiModelForm):
form_classes = {
'contato': ContactForm,
'telefone': PhoneInlineFormSet,
}
def __init__(self, *args, **kwargs):
instance = kwargs.pop('instance', None)
if instance is not None:
kwargs['instance'] = {
'contact': instance,
'phone': instance,
}
super(ContactPhoneForm, self).__init__(*args, **kwargs)
In my views.py
class ContactCreate(CreateView):
form_class = ContatoTelefoneForm
template_name = "forms/contato.html"
success_url = reverse_lazy('home')
success_message = "Contato cadastro com sucesso."
def form_valid(self, form):
contato = form['contact'].save()
telefone = form['phone'].save(commit=False)
telefone.contato = contato
telefone.save()
return super(ContactCreate, self).form_valid(form)
def get_success_url(self):
redirect_to = self.success_url
if not is_safe_url(url=redirect_to, host=self.request.get_host()):
redirect_to = self.success_url
return redirect_to
Once again, very thank you.
Atenciosamente,
Flaudizio B. S. Filho
82.8809.4382 (OI)
82.9662.3482 (TIM)
On Tue, Aug 2, 2016 at 11:16 AM, Rocky Meza [email protected]
wrote:
Hi @flaudizio https://github.com/flaudizio,
Are you talking about MultiForm?
You can use an a FormSet inside of a MultiForm. There is an example of
using an inline formset inside of a MultiForm in the tests:
https://github.com/fusionbox/django-betterforms/blob/master/tests/forms.py#L129-L146Is that what you were thinking?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#43 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHDA39tNsbeIu8hK_-WRByPE4yAHDbgtks5qb1EygaJpZM4JakZS
.
from django-betterforms.
Oh darn, I think you are running into the #41 bug. I'm going to close this bug in favor of that one. I think perhaps I have a solution for it in the #44 PR.
from django-betterforms.
Hi,
can you show the example using inline ?
I just haven't this (in view):
AttributeError
'list' object has no attribute 'contato'
contato = form['contato'].save()
telefone = form['telefone'].save(commit=False)
telefone.contato = contato
telefone.save()
Thank's and sorry for work.
from django-betterforms.
Related Issues (20)
- can't set attribute cleaned_data in form clean method HOT 9
- MultiModelForm with django.contrib.auth.forms.PasswordChangeForm
- MultiForm with separate submit buttons HOT 1
- Use dict instead of Context in for support with Django v1.11
- Kwargs should contain 'queryset' when child is a FormSet on edition HOT 1
- Multiform kwargs are copied to ALL form_classes instead of only to the ones that need them HOT 2
- Using MultiForm with Formset
- Release HOT 4
- Typo in documentation: BaseForm should be renamed into BetterForm
- Cannot override Multiform.clean()
- __init__() got an unexpected keyword argument 'request'
- Is it the project still alive? Django 3 support? HOT 18
- How to pass initial values to FilterForm
- AttributeError: Name Conflict in fieldset `Plate Description`. The name(s) `['i']` appear multiple times.
- Error while deploying on Elastic beanstalk HOT 1
- "Newline not allowed" when installing the package. Setuptools won't allow multiline descriptions anymore. HOT 1
- crispy forms raises ``Could not resolve form field``
- No use of default rendering? HOT 1
- is_valid() does not handle clean() not returning a value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-betterforms.