Skip to content

Commit

Permalink
Add basic many-to-many quota table
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov authored and lanseg committed Dec 24, 2024
1 parent 85c8ccb commit f461669
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
13 changes: 10 additions & 3 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
OrderItem,
Pricing,
Product,
ProductFormat)
ProductFormat,
ProductQuota)

UserModel = get_user_model()

Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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)
25 changes: 18 additions & 7 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand All @@ -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):
"""
Expand Down

0 comments on commit f461669

Please sign in to comment.