From 613cbc50e1d1f1c5529ca0e9cae81a03d0c4dd9b Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Thu, 5 Jun 2025 16:05:15 +0300 Subject: [PATCH] Features: Prometheus addons --- core/models.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/core/models.py b/core/models.py index e36436d8..43604541 100644 --- a/core/models.py +++ b/core/models.py @@ -36,6 +36,7 @@ from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode from django.utils.translation import gettext_lazy as _ from django_extensions.db.fields import AutoSlugField +from django_prometheus.models import ExportModelOperationsMixin from mptt.fields import TreeForeignKey from mptt.models import MPTTModel @@ -52,7 +53,7 @@ from payments.models import Transaction logger = logging.getLogger(__name__) -class AttributeGroup(NiceModel): +class AttributeGroup(ExportModelOperationsMixin("attribute_group"), NiceModel): is_publicly_visible = True parent = ForeignKey( @@ -79,7 +80,7 @@ class AttributeGroup(NiceModel): verbose_name_plural = _("attribute groups") -class Attribute(NiceModel): +class Attribute(ExportModelOperationsMixin("attribute"), NiceModel): is_publicly_visible = True categories = ManyToManyField( @@ -125,7 +126,7 @@ class Attribute(NiceModel): verbose_name_plural = _("attributes") -class AttributeValue(NiceModel): +class AttributeValue(ExportModelOperationsMixin("attribute_value"), NiceModel): is_publicly_visible = True attribute = ForeignKey( @@ -157,7 +158,7 @@ class AttributeValue(NiceModel): verbose_name_plural = _("attribute values") -class Category(NiceModel, MPTTModel): +class Category(ExportModelOperationsMixin("category"), NiceModel, MPTTModel): is_publicly_visible = True image = ImageField( @@ -220,7 +221,7 @@ class Category(NiceModel, MPTTModel): ordering = ["tree_id", "lft"] -class Brand(NiceModel): +class Brand(ExportModelOperationsMixin("brand"), NiceModel): is_publicly_visible = True name = CharField( @@ -266,7 +267,7 @@ class Brand(NiceModel): verbose_name_plural = _("brands") -class Product(NiceModel): +class Product(ExportModelOperationsMixin("product"), NiceModel): is_publicly_visible = True category = ForeignKey( @@ -371,7 +372,7 @@ class Product(NiceModel): return quantity -class Vendor(NiceModel): +class Vendor(ExportModelOperationsMixin("vendor"), NiceModel): is_publicly_visible = False authentication = JSONField( @@ -406,7 +407,7 @@ class Vendor(NiceModel): ] -class Feedback(NiceModel): +class Feedback(ExportModelOperationsMixin("feedback"), NiceModel): is_publicly_visible = True comment = TextField( # noqa: DJ001 @@ -439,7 +440,7 @@ class Feedback(NiceModel): verbose_name_plural = _("feedbacks") -class Order(NiceModel): +class Order(ExportModelOperationsMixin("order"), NiceModel): is_publicly_visible = False billing_address = ForeignKey( @@ -792,7 +793,7 @@ class Order(NiceModel): return self -class OrderProduct(NiceModel): +class OrderProduct(ExportModelOperationsMixin("order_product"), NiceModel): is_publicly_visible = False buy_price = FloatField( @@ -899,7 +900,7 @@ class OrderProduct(NiceModel): return "" -class ProductTag(NiceModel): +class ProductTag(ExportModelOperationsMixin("product_tag"), NiceModel): is_publicly_visible = True tag_name = CharField( @@ -924,7 +925,7 @@ class ProductTag(NiceModel): verbose_name_plural = _("product tags") -class ProductImage(NiceModel): +class ProductImage(ExportModelOperationsMixin("product_image"), NiceModel): is_publicly_visible = True alt = CharField( @@ -963,7 +964,7 @@ class ProductImage(NiceModel): verbose_name_plural = _("product images") -class PromoCode(NiceModel): +class PromoCode(ExportModelOperationsMixin("promocode"), NiceModel): is_publicly_visible = False code = CharField( @@ -1061,7 +1062,7 @@ class PromoCode(NiceModel): return amount -class Promotion(NiceModel): +class Promotion(ExportModelOperationsMixin("promotion"), NiceModel): is_publicly_visible = True discount_percent = IntegerField( @@ -1098,7 +1099,7 @@ class Promotion(NiceModel): return str(self.id) -class Stock(NiceModel): +class Stock(ExportModelOperationsMixin("stock"), NiceModel): is_publicly_visible = False vendor = ForeignKey( @@ -1153,7 +1154,7 @@ class Stock(NiceModel): verbose_name_plural = _("stock entries") -class Wishlist(NiceModel): +class Wishlist(ExportModelOperationsMixin("wishlist"), NiceModel): is_publicly_visible = False products = ManyToManyField( @@ -1214,7 +1215,7 @@ class Wishlist(NiceModel): return self -class DigitalAssetDownload(NiceModel): +class DigitalAssetDownload(ExportModelOperationsMixin("attribute_group"), NiceModel): is_publicly_visible = False order_product = OneToOneField(to=OrderProduct, on_delete=CASCADE, related_name="download") @@ -1235,7 +1236,7 @@ class DigitalAssetDownload(NiceModel): return f"https://api.{config.BASE_URL}/download/{urlsafe_base64_encode(force_bytes(self.order_product.uuid))}" -class Documentary(NiceModel): +class Documentary(ExportModelOperationsMixin("attribute_group"), NiceModel): is_publicly_visible = True product = ForeignKey(to=Product, on_delete=CASCADE, related_name="documentaries") @@ -1256,7 +1257,7 @@ class Documentary(NiceModel): return self.document.name.split(".")[-1] or _("unresolved") -class Address(NiceModel): +class Address(ExportModelOperationsMixin("address"), NiceModel): is_publicly_visible = False address_line = TextField( # noqa: DJ001