From: Tollef Fog Heen Date: Mon, 7 May 2012 09:24:39 +0000 (+0200) Subject: Add createinvoice/detailinvoice foo X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c6004e4a695c073cd2711472141edadefd3c45e;p=peojumk Add createinvoice/detailinvoice foo --- diff --git a/invoice/models.py b/invoice/models.py index 8ec1945..64f0710 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -34,6 +34,9 @@ class VAT(models.Model): verbose_name = _('VAT level') verbose_name_plural = _('VAT levels') + def get_invoicelines(self): + return self.invoiceline_set.select_related('invoice') + def __unicode__(self): return '%s' % self.name diff --git a/invoice/urls.py b/invoice/urls.py index f7b5850..9eb3ac9 100644 --- a/invoice/urls.py +++ b/invoice/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import patterns, include, url import django.contrib.auth.views from invoice.views import UpdateClient, DeleteClient, CreateClient, DetailClient, \ - CreateInvoice + CreateInvoice, DetailInvoice import invoice.views @@ -13,4 +13,5 @@ urlpatterns = patterns('invoice.views', url(r'^client/(?P\d+)/delete$', DeleteClient.as_view(), name='c_delete'), url(r'^accounts/login/$', django.contrib.auth.views.login), url(r'^invoice/new$', CreateInvoice.as_view(), name="invoice_new"), + url(r'^invoice/(?P\d+)$', DetailInvoice.as_view()), ) diff --git a/invoice/views.py b/invoice/views.py index 283ee07..a7a4b31 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -7,7 +7,10 @@ from django.views.generic.create_update import get_model_and_form_class, apply_e from django.views.generic import UpdateView, DeleteView, CreateView, DetailView from django.utils.decorators import method_decorator -from invoice.models import Client, Invoice +from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet +from extra_views.generic import GenericInlineFormSet + +from invoice.models import Client, Invoice, InvoiceLine from invoice.forms import ClientForm, InvoiceForm @login_required @@ -15,6 +18,8 @@ def index(request): clients = Client.objects.all() return render_to_response('invoice/index.html', {'clients': clients}) +# ------------------- CLIENT --------------- + class DetailClient(DetailView): model = Client @method_decorator(login_required) @@ -47,11 +52,22 @@ class DeleteClient(DeleteView): @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(DeleteClient, self).dispatch(*args, **kwargs) - # ------------------- INVOICE --------------- -class CreateInvoice(CreateView): + +class InvoiceLineInline(InlineFormSet): + model = InvoiceLine + +class DetailInvoice(DetailView): + model = Invoice + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(DetailInvoice, self).dispatch(*args, **kwargs) + +class CreateInvoice(CreateWithInlinesView): model = Invoice + inlines = [InvoiceLineInline] form_class = InvoiceForm success_url = '/' diff --git a/templates/invoice/invoice_form.html b/templates/invoice/invoice_form.html index 984348f..f381525 100644 --- a/templates/invoice/invoice_form.html +++ b/templates/invoice/invoice_form.html @@ -5,7 +5,10 @@
{% csrf_token %}
    - {{ form.as_ul}} + {{ form.as_ul }} +{% for formset in inlines %} +
  • {{ formset }}
  • +{% endfor %}