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 %}
<script src="{{ STATIC_URL }}js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function() {
$(".inline.{{ invoiceformset.prefix }}").formset({
prefix: "{{ invoiceformset.prefix }}",
})
})
</script>
<div class="the-box no-border">
<form action="/store_invoice/{{store.id}}/invoice/add/" method="post">{%
csrf_token %}
<div class="row">
<div class="col-sm-4">
<label>Customer</label>
{{invoiceform}}
</div>
</div>
<fieldset>
<legend>Order Items</legend>
{{ invoiceformset.management_form }}
{{ invoiceformset.non_form_errors }}
{% for form in invoiceformset %}
{{ form.id }}
<div class="inline {{ invoiceformset.prefix }}">
{{form}}
</div>
{% endfor %}
</fieldset>
<button type="submit" class="btn btn-success">Add Order</button>
</form>
</div>
{% 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 autopopulate by corresponding
Product details(Particular,unit price and tax) and it must be in
inlineformset, for every 'add another' it must be autopopulate, like above
reference link.
thanks in advance
<https://lh4.googleusercontent.com/-CBWl2IHpxMM/VNyO5GBTYZI/AAAAAAAAAUw/DDvqIlYXmkk/s1600/Screenshot%2Bfrom%2B2015-02-12%2B11%3A30%3A21.png>
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/bdab6549-0749-4ec4-8f67-c85a93cd5c2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.