class UserTaxesMultiForm(MultiModelForm): form_classes = { 'user_tax_form': MyForm, 'user_discount_form': DiscountForm, 'user_shiping_form': ShipmentForm, }
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
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}
--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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.
For more options, visit https://groups.google.com/d/optout.
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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.
For more options, visit https://groups.google.com/d/optout.
Sunil Kothiyal
<form action="link to a url" method="post></form>
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOh93neYb8me%3DkLOigxMjeBLETPB2_bszL8nB4WhZsEreHwJMQ%40mail.gmail.com.
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/CAKNYNB%3Db8NnRnONyy_PrAovnqko1NQ4CA%2BeP-2mtK24-CGcxwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
in views.py
class ClassesAddView(LoginRequiredMixin,View):
classesFormClass = ClassesRegForm
daysFormClass = DaysForm
template_name = 'qing/classes.html'
def get(self,request,role='NoRole'):
classesForm = self.classesFormClass()
context['form'] = classesForm
daysForm = self.daysFormClass()
context['daysform'] = daysForm
return render(request,self.template_name, context)
def post(self, request, *args, **kwargs):
classesForm = self.classesFormClass(request.POST)
daysForm = self.daysFormClass(request.POST)
if classesForm.is_valid() and daysForm.is_valid():
days = str(request.POST.getlist('days'))
reference = request.POST['reference']
classes = classesForm.save()
classes = Classes.objects.get(reference=reference)
classes.days = days
classes.save()
else:
classesForm = self.classesFormClass(request.POST)
context['form'] = classesForm
daysForm = self.daysFormClass(request.POST)
context['daysform'] = daysForm
context['datavalid'] = False
return render(request, self.template_name, context)
return HttpResponseRedirect(reverse('classesadd',args=(role,)))
in forms.py
class ClassesForm(ModelForm):
class Meta:
model = Classes
fields = ['reference','course','teachers',etc...]
class DaysForm(forms.Form):
OPTIONS = (
("Sunday", "Sunday"),
("Monday", "Monday"),
("Tuesday", "Tuesday"),
("Wednesday", "Wednesday"),
("Thursday", "Thursday"),
("Friday", "Friday"),
("Saturday", "Saturday"),
)
days = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
choices=OPTIONS)
<form action="/YOURFIRSTFORMURL" method="post" id="target">
{% csrf_token %}
<div class="form-group">
<label for="fname">First Name:</label>
<input type="text" class="form-control" id="fname" placeholder="First Name" name="fname">
</div>
<div class="form-group">
<label for="lname">Last Name:</label>
<input type="text" class="form-control" id="lname" placeholder="Last Name" name="lname">
</div>
<div class="form-group">
<label for="lname">Gender:</label>
<input type="text" class="form-control" id="gender" placeholder="Last Name" name="gender">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<script>
$( "#target" ).submit(function( event ) {
var form = $("form").serialize();
$.ajax({
url: '',
data: form ,
success: function (data) {
toastr["success"]("New Student Added !")
}
});
event.preventDefault();
});
</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
def update(request):
fname = request.GET.get('fname')
lname = request.GET.get('lname')
gender = request.GET.get('gender')
student.objects.create(firstname=fname,lastname=lname,gender=gender)
return JsonResponse ({'Success':'Success'})
--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/122a47d7-5cdd-47ee-8524-fb55fb80285e%40googlegroups.com.
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/CANjUscDRzDpXMc3E30hH0tEDbaT--JLgnJGtTOpjoqfjkzHyzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB%3DWnGdxtS74QsphmWxCwyUa5b%3DZEEpeji0s6%3DkPRz9GtB0uAw%40mail.gmail.com.
HI Everett White , Please suggest solution i am trying since 3 days, I want Django model update if exist. I will very thankful to you.
--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/6643b26e-d00d-438d-9d24-d383c857fada%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA%3Diw_-QFgL1DEZMmYMzpZRUcr5aY%2BGCBv_dJJB%3DdgyRyJJwQQ%40mail.gmail.com.