CRUD fonctionnel
This commit is contained in:
parent
1039d1e6d6
commit
43182c04aa
@ -26,8 +26,11 @@ router.register(r'orders', OrderViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^create/', views.OrderCreateView.as_view(), name='create'),
|
||||
url(r'^api/', include(router.urls)),
|
||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
url(r'^$', views.OrderIndexView.as_view(), name='index'),
|
||||
url(r'^(?P<pk>[-\w]+)/$', views.OrderDetailView.as_view(), name='detail'),
|
||||
url(r'^api/', include(router.urls)),
|
||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
url(r'^(?P<pk>[-\w]+)/delete/$', views.OrderDeleteView.as_view(), name='delete'),
|
||||
url(r'^(?P<pk>[-\w]+)/update/$', views.OrderUpdateView.as_view(), name='update'),
|
||||
]
|
||||
|
@ -13,15 +13,15 @@ class Order(models.Model):
|
||||
order_id = models.CharField(max_length=20, primary_key=True)
|
||||
order_mrid = models.CharField(max_length=20)
|
||||
order_refid = models.CharField(max_length=20)
|
||||
order_external_id = models.CharField(max_length=20, null=True)
|
||||
order_external_id = models.CharField(max_length=20, null=True, blank=True)
|
||||
# Colonne unique pour le order_purchase_date et order_purchase_heure because DateTime
|
||||
order_purchase = models.DateTimeField(null=True)
|
||||
order_purchase = models.DateTimeField(null=True, blank=True)
|
||||
order_amount = models.FloatField()
|
||||
order_tax = models.FloatField(null=True)
|
||||
order_tax = models.FloatField(null=True, blank=True)
|
||||
order_shipping = models.FloatField()
|
||||
order_commission = models.FloatField()
|
||||
order_processing_fee = models.FloatField()
|
||||
order_comments = models.TextField(null=True)
|
||||
customer_id = models.CharField(max_length=20, null=True)
|
||||
order_ip = models.GenericIPAddressField(null=True)
|
||||
order_comments = models.TextField(null=True, blank=True)
|
||||
customer_id = models.CharField(max_length=20, null=True, blank=True)
|
||||
order_ip = models.GenericIPAddressField(null=True, blank=True)
|
||||
order_items = models.IntegerField()
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.views.generic import ListView, DetailView, DeleteView, UpdateView, CreateView
|
||||
|
||||
from rest_framework import serializers, viewsets
|
||||
|
||||
@ -15,6 +16,30 @@ class OrderDetailView(DetailView):
|
||||
model = Order
|
||||
|
||||
|
||||
class OrderDeleteView(DeleteView):
|
||||
template_name = 'orders/order/delete.html'
|
||||
model = Order
|
||||
success_url = reverse_lazy('index')
|
||||
|
||||
|
||||
class OrderUpdateView(UpdateView):
|
||||
template_name = 'orders/order/update.html'
|
||||
model = Order
|
||||
success_url = reverse_lazy('index')
|
||||
fields = ['marketplace', 'idFlux', 'order_mrid', 'order_refid', 'order_external_id',
|
||||
'order_purchase', 'order_amount', 'order_tax', 'order_shipping', 'order_commission',
|
||||
'order_processing_fee', 'order_comments', 'customer_id', 'order_ip', 'order_items']
|
||||
|
||||
|
||||
class OrderCreateView(CreateView):
|
||||
template_name = 'orders/order/create.html'
|
||||
model = Order
|
||||
success_url = reverse_lazy('index')
|
||||
fields = ['marketplace', 'idFlux', 'order_mrid', 'order_refid', 'order_external_id',
|
||||
'order_purchase', 'order_amount', 'order_tax', 'order_shipping', 'order_commission',
|
||||
'order_processing_fee', 'order_comments', 'customer_id', 'order_ip', 'order_items']
|
||||
|
||||
|
||||
class OrderSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Order
|
||||
|
@ -14,6 +14,14 @@
|
||||
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-default">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="/">Orders Management</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{% block body %}{% endblock %}
|
||||
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
|
12
templates/orders/order/create.html
Normal file
12
templates/orders/order/create.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'orders/base.html' %}
|
||||
|
||||
{% block title %}Create an order{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Create"/>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
12
templates/orders/order/delete.html
Normal file
12
templates/orders/order/delete.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'orders/base.html' %}
|
||||
|
||||
{% block title %}Confirm deletion of {{ object.order_id }}'s order{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete order "{{ object.order_id }}"?</p>
|
||||
<input type="submit" value="Confirm"/>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
@ -4,7 +4,6 @@
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
|
||||
<h2>Order {{ object.order_id }}</h2>
|
||||
|
||||
<ul>
|
||||
|
@ -4,7 +4,11 @@
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<h1>Orders</h1>
|
||||
<p>
|
||||
<a href="/create">
|
||||
<i class="glyphicon glyphicon-plus"></i> Create new order
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
@ -49,7 +53,7 @@
|
||||
<td>{{ order.order_ip }}</td>
|
||||
<td>{{ order.order_items }}</td>
|
||||
<td>
|
||||
<a href="/{{ order.order_id }}/edit">
|
||||
<a href="/{{ order.order_id }}/update">
|
||||
<i class="glyphicon glyphicon-pencil"></i>
|
||||
</a>
|
||||
</td>
|
||||
|
14
templates/orders/order/update.html
Normal file
14
templates/orders/order/update.html
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends 'orders/base.html' %}
|
||||
|
||||
{% block title %}Update {{ object.order_id }}'s order{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<h2>Order {{ object.order_id }}</h2>
|
||||
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Update"/>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user