🚨 format python code using black
This commit is contained in:
1 parent
9c4a5b3d84
commit
a052397990
24 files changed
+643
-407
No files matched your search
+18
-9
@@ -8,33 +8,42 @@ from main.models import Product, OrderLine, Order
|
||||
class ProductSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = '__all__'
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ProductStatSerializer(ModelSerializer):
|
||||
EXTERNAL_USER = 'Ekstern'
|
||||
EXTERNAL_USER = "Ekstern"
|
||||
counts = serializers.SerializerMethodField()
|
||||
|
||||
def _format_counts(self, per_user):
|
||||
per_user = list(per_user)
|
||||
for row in per_user:
|
||||
first = row.pop('order__customer__first_name')
|
||||
last = row.pop('order__customer__last_name')
|
||||
first = row.pop("order__customer__first_name")
|
||||
last = row.pop("order__customer__last_name")
|
||||
if first is None:
|
||||
who = self.EXTERNAL_USER
|
||||
else:
|
||||
who = '{} {}'.format(first, last)
|
||||
row['full_name'] = who
|
||||
who = "{} {}".format(first, last)
|
||||
row["full_name"] = who
|
||||
|
||||
return per_user
|
||||
|
||||
def get_counts(self, obj):
|
||||
name_fields = ['order__customer__first_name', 'order__customer__last_name']
|
||||
name_fields = ["order__customer__first_name", "order__customer__last_name"]
|
||||
per_user = OrderLine.objects.filter(product=obj)
|
||||
per_user = per_user.values(*name_fields).annotate(amount_total=Sum('amount')).order_by('-amount_total')
|
||||
per_user = per_user.values(*name_fields).annotate(amount_total=Sum("amount")).order_by("-amount_total")
|
||||
|
||||
return self._format_counts(per_user)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ['id', 'name', 'description', 'image', 'inventory_amount', 'active', 'created', 'counts']
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"image",
|
||||
"inventory_amount",
|
||||
"active",
|
||||
"created",
|
||||
"counts",
|
||||
]
|
||||
Reference in new issue
Block a user