Skip to content

Commit d241130

Browse files
author
Eric Harmeling
committed
formatted django code
1 parent f4b2bdb commit d241130

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

python/django/cockroach_example/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from django.db import models
22

3+
34
class Customers(models.Model):
45
id = models.AutoField(primary_key=True)
56
name = models.CharField(max_length=250)
67

8+
79
class Products(models.Model):
810
id = models.AutoField(primary_key=True)
911
name = models.CharField(max_length=250)
1012
price = models.DecimalField(max_digits=18, decimal_places=2)
1113

14+
1215
class Orders(models.Model):
1316
id = models.AutoField(primary_key=True)
1417
subtotal = models.DecimalField(max_digits=18, decimal_places=2)
15-
customer = models.ForeignKey(Customers, on_delete=models.CASCADE, null=True)
18+
customer = models.ForeignKey(
19+
Customers, on_delete=models.CASCADE, null=True)
1620
product = models.ManyToManyField(Products)
17-

python/django/cockroach_example/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from .models import *
1414

1515
# Warning: Do not use retry_on_exception in an inner nested transaction.
16+
17+
1618
def retry_on_exception(view, num_retries=3, on_failure=HttpResponse(status=500), delay_=0.5, backoff_=1.5):
1719
@wraps(view)
1820
def retry(*args, **kwargs):
@@ -32,10 +34,12 @@ def retry(*args, **kwargs):
3234
return on_failure
3335
return retry
3436

37+
3538
class PingView(View):
3639
def get(self, request, *args, **kwargs):
3740
return HttpResponse("python/django", status=200)
3841

42+
3943
@method_decorator(csrf_exempt, name='dispatch')
4044
class CustomersView(View):
4145
def get(self, request, id=None, *args, **kwargs):
@@ -61,10 +65,11 @@ def delete(self, request, id=None, *args, **kwargs):
6165
return HttpResponse(status=404)
6266
Customers.objects.filter(id=id).delete()
6367
return HttpResponse(status=200)
64-
68+
6569
# The PUT method is shadowed by the POST method, so there doesn't seem
6670
# to be a reason to include it.
6771

72+
6873
@method_decorator(csrf_exempt, name='dispatch')
6974
class ProductView(View):
7075
def get(self, request, id=None, *args, **kwargs):
@@ -86,6 +91,7 @@ def post(self, request, *args, **kwargs):
8691
# The REST API outlined in the github does not say that /product/ needs
8792
# a PUT and DELETE method
8893

94+
8995
@method_decorator(csrf_exempt, name='dispatch')
9096
class OrdersView(View):
9197
def get(self, request, id=None, *args, **kwargs):
@@ -94,7 +100,7 @@ def get(self, request, id=None, *args, **kwargs):
94100
else:
95101
orders = list(Orders.objects.filter(id=id).values())
96102
return JsonResponse(orders, safe=False)
97-
103+
98104
@retry_on_exception
99105
@atomic
100106
def post(self, request, *args, **kwargs):

0 commit comments

Comments
 (0)