Giter VIP home page Giter VIP logo

Comments (4)

rockymeza avatar rockymeza commented on September 21, 2024

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.

flaudizio avatar flaudizio commented on September 21, 2024

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-L146

Is 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.

rockymeza avatar rockymeza commented on September 21, 2024

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.

flaudizio avatar flaudizio commented on September 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.