following are my models they are not related to each other.----

class StUserTaxDetails(models.Model):
user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING, null=False,
default=None)
tax_name = models.CharField(max_length=50)
tax_rate = models.FloatField()


def __str__(self):
return self.tax_name

class Meta:
managed = True
db_table = 'st_user_tax_details'


class StUserDiscountDetails(models.Model):
creater = models.OneToOneField(
UserModel, on_delete=models.CASCADE, blank=False)
discount_name = models.CharField(max_length=50)
discount_rate = models.FloatField()

class Meta:
managed = True
db_table = 'st_user_discount_details'


On Fri, Sep 7, 2018 at 4:50 PM Mohammad Aqib <[email protected]>
wrote:

> Show your models.py.
>
> On Fri, Sep 7, 2018 at 4:13 PM Django Lover <[email protected]>
> wrote:
>
>>
>> I have one page, which I have to show three model form and three
>> different submit button for each.
>>
>> My question is how I can save these three form individually?
>>
>> FOLLOWING IS CODE:-
>>
>> **form.py**
>>
>>
>> class UserTaxesMultiForm(MultiModelForm):
>>    form_classes = {
>>        'user_tax_form': MyForm,
>>        'user_discount_form': DiscountForm,
>>        'user_shiping_form': ShipmentForm,
>>    }
>>
>> *Note- myForm, DiscountForm, ShipmentForm are model forms. like
>> following-*
>>
>> class MyForm(forms.ModelForm):
>>        prefix = 'tax'
>>        class Meta:
>>            model = StUserTaxDetails
>>            fields = ('tax_name', 'tax_rate')
>>
>>        tax_name = forms.CharField(max_length=10,
>>         widget=forms.TextInput(),
>>         required=True, label="tax name")
>>
>>         tax_rate = forms.FloatField(required=True,  label="tax rate")
>>
>>
>>         error_messages  = {
>>            'required': _('fields are required.'),
>>        }
>>
>>         def clean_title(self):
>>            return self.cleaned_data['tax_name']
>>
>>         def clean(self):
>>            tax_name = self.cleaned_data.get('tax_name')
>>            tax_rate = self.cleaned_data.get('tax_rate')
>>
>>             if not tax_name and not tax_rate:
>>                raise forms.ValidationError(
>>                    self.error_messages['required'],
>>                    code='required',
>>                )
>>            return self.cleaned_data
>>
>> **view.py**
>> class AddTaxView(LoginRequiredMixin, CreateView):
>>    template_name = 'invoices/add_tax.html'
>>    form_class = UserTaxesMultiForm
>>    success_url = '/add/tax/'
>>
>>    *{WHAT IS THE CODE HERE FOR THE POST METHOD TO SAVE DATA ACORDING
>> DIFFRENT FORM SUBMIT} *
>>
>>
>>
>>
>> **HTML**
>>
>>
>>
>> <form method="POST">
>> {% form.user_tax_form%}
>>
>> <input type="submit" value="Submit" />
>> </form>
>>
>> <form method="POST">
>> {% form.user_discount_form%}
>>
>> <input type="submit" value="Submit" />
>> </form>
>>
>> <form method="POST">
>> {% form.user_shiping_form%}
>>
>> <input type="submit" value="Submit" />
>> </form>
>>
>> PLEASE HELP
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/45a017a3-9633-426f-81e1-b261189e714a%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/45a017a3-9633-426f-81e1-b261189e714a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Mohd Aqib
> Software Engineer
> 9873141865
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/HlJSOz8zgwM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOh93neYb8me%3DkLOigxMjeBLETPB2_bszL8nB4WhZsEreHwJMQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOh93neYb8me%3DkLOigxMjeBLETPB2_bszL8nB4WhZsEreHwJMQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
*Thanks & Regards,*

*Sunil Kothiyal*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%3DWnGcyfiN2txQODBP86m%2BwQ87V-VbpKBWKy_AUv%3DDviunpLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to