diff --git a/api/admin.py b/api/admin.py index 4dd29c7..d604dd3 100644 --- a/api/admin.py +++ b/api/admin.py @@ -24,7 +24,8 @@ OrderItem, Pricing, Product, - ProductFormat) + ProductFormat, + ProductQuota) UserModel = get_user_model() @@ -188,17 +189,22 @@ def response_change(self, request, obj): return HttpResponseRedirect(redirect_url) return super().response_change(request, obj) +class ProductQuotaAdmin(CustomGeoModelAdmin): + pass + +class ProductQuotaInline(admin.TabularInline): + model = ProductQuota + extra = 1 class ProductAdmin(CustomGeoModelAdmin): save_as = True - inlines = [ProductFormatInline] + inlines = [ProductFormatInline, ProductQuotaInline] raw_id_fields = ('metadata', 'group') exclude = ('ts',) search_fields = ['label'] list_filter = ('product_status',) readonly_fields = ('thumbnail_tag',) - class AbstractIdentityAdmin(CustomModelAdmin): list_display = ['last_name', 'first_name', 'company_name', 'email'] search_fields = ['first_name', 'last_name', 'company_name', 'email'] @@ -281,3 +287,4 @@ def response_change(self, request, obj): admin.site.register(Pricing, PricingAdmin) admin.site.register(Product, ProductAdmin) admin.site.register(ProductFormat) +admin.site.register(ProductQuota, ProductQuotaAdmin) \ No newline at end of file diff --git a/api/models.py b/api/models.py index cca725e..d437aae 100644 --- a/api/models.py +++ b/api/models.py @@ -6,6 +6,7 @@ from django.contrib.gis.db import models from django.contrib.gis.geos import MultiPolygon, Polygon from django.contrib.auth import get_user_model +from django.contrib.auth.models import Group from django.contrib.postgres.search import SearchVectorField from django.contrib.postgres.indexes import GinIndex, BTreeIndex from django.utils import timezone @@ -412,7 +413,6 @@ class Meta: def __str__(self): return self.name - class Product(models.Model): """ A product is mostly a table or a raster. It can also be a group of products. @@ -482,12 +482,7 @@ class ProductStatus(models.TextChoices): default=settings.DEFAULT_PRODUCT_THUMBNAIL_URL, ) ts = SearchVectorField(null=True) - bbox = settings.DEFAULT_EXTENT - geom = models.MultiPolygonField( - _("geom"), - srid=settings.DEFAULT_SRID, - default=MultiPolygon(Polygon.from_bbox(bbox)), - ) + class Meta: db_table = "product" @@ -510,6 +505,22 @@ def thumbnail_tag(self): thumbnail_tag.short_description = _("thumbnail") +class ProductQuota(models.Model): + user_group = models.ForeignKey( + Group, models.CASCADE, verbose_name=_("user_group") + ) + product = models.ForeignKey( + Product, models.CASCADE, verbose_name=_("product"), default=1 + ) + bbox = settings.DEFAULT_EXTENT + geom = models.MultiPolygonField( + _("geom"), + srid=settings.DEFAULT_SRID, + default=MultiPolygon(Polygon.from_bbox(bbox))) + quota = models.FloatField(_("quota")) + + def __str__(self): + return f'Quota for "{self.user_group}" in "{self.product}" is "{self.quota}"' class Order(models.Model): """