I'm trying to do this following link feature in django,
http://demo.smarttutorials.net/jquery-autocomplete/
Here by choosing country the rest of the fields will be auto populated,
like this i'm trying to achieve in django, If any idea pls tell me it will
be very great for me
This is Product table,by this i will add many products
*models.py*
class Product(models.Model):
store = models.ForeignKey(Store)
code = models.CharField(verbose_name='Product Code', max_length=128,
blank=False)
name = models.CharField(verbose_name='Product Name', max_length=128,
blank=False)
unit_price = models.FloatField(verbose_name='Unit Price', blank=False)
in_stock = models.IntegerField(verbose_name='In Stock', default=0,
blank=False)
This is Invoice order table, in this i will get customer details
class Invoice(models.Model):
customer = models.ForeignKey(Customer)
date = models.DateTimeField(auto_now=True, blank=False)
This in Invoice Item order table which is in inline formset
class InvoiceItem(models.Model):
invoice = models.ForeignKey(Invoice)
product = models.ForeignKey(Product)
particular = models.CharField(verbose_name='Particular', max_length=128,
blank=False)
quantity = models.IntegerField(verbose_name='Quantity', default=0)
unit_price = models.FloatField(verbose_name='Unit Price', blank=False)
tax_rate_percentage = models.FloatField(verbose_name='Tax Rate Percentage',
blank=False)
*views.py*
I'm trying to raise invoice by autopopulate feature.
def add_invoice(request):
store = Store.objects.get(id=pk)
product = Product.objects.filter(store=store)
context = RequestContext(request)
InvoiceItemInlineFormSet = inlineformset_factory(Invoice, InvoiceItem,
extra = 1,exclude=('invoice',))
if request.method == 'POST':
invoiceform = InvoiceForm(request.POST)
invoiceformset = InvoiceItemInlineFormSet(request.POST)
if invoiceform.is_valid() and invoiceformset.is_valid():
invoice = invoiceform.save(commit=False)
invoice.store = store
invoice.save()
invoiceformset.save(commit=False)
invoiceformset.instance = invoice
invoiceformset.save()
return HttpResponseRedirect('/store_invoice/%s/invoice/'% pk)
else:
invoiceform = InvoiceForm()
invoiceformset = InvoiceItemInlineFormSet()
args = {}
args.update(csrf(request))
args = {'email':email,'store':store,'invoiceform':invoiceform,
'invoiceformset':invoiceformset}
return render_to_response('invoice/invoice_add.html',args,context)
*invoice_add.html*
{% extends "base_site.html" %}
{% load staticfiles %}
{% block title %}Add New Order | Finvoicez{% endblock %}
{% block page-heading %}Add New Order{% endblock %}
{% block content %}
$(function() {
$(".inline.{{ invoiceformset.prefix }}").formset({
prefix: "{{ invoiceformset.prefix }}",
})
})
{% csrf_token %}
Customer
{{invoiceform}}
Order Items
{{ invoiceformset.management_form }}
{{ invoiceformset.non_form_errors }}
{% for form in invoiceformset %}
{{ form.id }}
{{form}}
{% endfor %}
Add Order
{% endblock %}
Here i'm trying to bring when i'm adding Invoice Item , by selecting the
product code the rest of fields want to be auto populate by corresponding
Product details(Particular,unit price and tax) and it must be in
inlineformset, for every 'add another' it must be auto populate, like above
reference link.
thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/6b9e44eb-0cbe-470d-aab8-0d24b0ba5540%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.