calculate remaining quota weight - product_id - change role permission serializer
This commit is contained in:
@@ -96,7 +96,7 @@ class RoleSerializer(serializers.ModelSerializer):
|
|||||||
representation['type'] = auth_serializer.OrganizationTypeSerializer(instance.type).data
|
representation['type'] = auth_serializer.OrganizationTypeSerializer(instance.type).data
|
||||||
if instance.permissions: # noqa
|
if instance.permissions: # noqa
|
||||||
permissions = instance.permissions.filter(is_active=True)
|
permissions = instance.permissions.filter(is_active=True)
|
||||||
representation['permissions'] = PermissionSerializer().permissions_structure_output(permissions)
|
representation['permissions'] = PermissionSerializer(permissions, many=True).data
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,6 @@ from django.apps import AppConfig
|
|||||||
class ProductConfig(AppConfig):
|
class ProductConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'apps.product'
|
name = 'apps.product'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import apps.product.signals
|
||||||
|
|||||||
@@ -64,10 +64,22 @@ class Product(BaseModel):
|
|||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def generate_product_id(self): # noqa
|
||||||
|
""" generate id for product from 10 """
|
||||||
|
|
||||||
|
last = Product.objects.filter(product_id__gte=10, product_id__lte=1999).order_by('-product_id').first()
|
||||||
|
if last:
|
||||||
|
next_code = last.product_id + 1
|
||||||
|
else:
|
||||||
|
next_code = 10
|
||||||
|
return next_code
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'name: {self.name} - type: {self.type}'
|
return f'name: {self.name} - type: {self.type}'
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.product_id:
|
||||||
|
self.product_id = self.generate_product_id() # set product id
|
||||||
super(Product, self).save(*args, **kwargs)
|
super(Product, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user