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
url(r'^client/(?P<pk>\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<pk>\d+)$', DetailInvoice.as_view()),
)
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
clients = Client.objects.all()
return render_to_response('invoice/index.html', {'clients': clients})
+# ------------------- CLIENT ---------------
+
class DetailClient(DetailView):
model = Client
@method_decorator(login_required)
@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 = '/'