Features: 1) Add CategoryTagType graphene object type with fields and filters; 2) Add tags field to CategoryType for associating category tags; 3) Add category_tags field in schema for querying category tag data.
Fixes: None; Extra: 1) Update imports to include `CategoryTag` and `CategoryTagType`.
This commit is contained in:
parent
fa588b59ae
commit
fbdc1bc243
2 changed files with 22 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ from core.models import (
|
|||
AttributeValue,
|
||||
Brand,
|
||||
Category,
|
||||
CategoryTag,
|
||||
Feedback,
|
||||
Order,
|
||||
OrderProduct,
|
||||
|
|
@ -119,6 +120,7 @@ class CategoryType(DjangoObjectType):
|
|||
NonNull(MinMaxPriceType),
|
||||
description=_("minimum and maximum prices for products in this category, if available."),
|
||||
)
|
||||
tags = DjangoFilterConnectionField(lambda: CategoryTagType, description=_("tags for this category"))
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
|
|
@ -464,6 +466,17 @@ class ProductTagType(DjangoObjectType):
|
|||
description = _("product tags")
|
||||
|
||||
|
||||
class CategoryTagType(DjangoObjectType):
|
||||
category_set = DjangoFilterConnectionField(CategoryType, description=_("tagged categories"))
|
||||
|
||||
class Meta:
|
||||
model = CategoryTag
|
||||
interfaces = (relay.Node,)
|
||||
fields = ("uuid", "tag_name", "name", "category_set")
|
||||
filter_fields = ["uuid", "tag_name", "name"]
|
||||
description = _("categories tags")
|
||||
|
||||
|
||||
class ConfigType(ObjectType):
|
||||
project_name = String(description=_("project name"))
|
||||
base_domain = String(description=_("company email"))
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ from core.graphene.mutations import (
|
|||
from core.graphene.object_types import (
|
||||
AttributeGroupType,
|
||||
BrandType,
|
||||
CategoryTagType,
|
||||
CategoryType,
|
||||
ConfigType,
|
||||
FeedbackType,
|
||||
|
|
@ -60,6 +61,7 @@ from core.models import (
|
|||
AttributeGroup,
|
||||
Brand,
|
||||
Category,
|
||||
CategoryTag,
|
||||
Feedback,
|
||||
Order,
|
||||
OrderProduct,
|
||||
|
|
@ -111,6 +113,7 @@ class Query(ObjectType):
|
|||
stocks = DjangoFilterConnectionField(StockType)
|
||||
wishlists = DjangoFilterConnectionField(WishlistType, filterset_class=WishlistFilter)
|
||||
product_tags = DjangoFilterConnectionField(ProductTagType)
|
||||
category_tags = DjangoFilterConnectionField(CategoryTagType)
|
||||
promotions = DjangoFilterConnectionField(PromotionType)
|
||||
promocodes = DjangoFilterConnectionField(PromoCodeType)
|
||||
brands = DjangoFilterConnectionField(BrandType, filterset_class=BrandFilter)
|
||||
|
|
@ -289,6 +292,12 @@ class Query(ObjectType):
|
|||
return ProductTag.objects.all()
|
||||
return ProductTag.objects.filter(is_active=True)
|
||||
|
||||
@staticmethod
|
||||
def resolve_category_tags(_parent, info, **kwargs):
|
||||
if info.context.user.has_perm("core.view_categorytag"):
|
||||
return CategoryTag.objects.all()
|
||||
return CategoryTag.objects.filter(is_active=True)
|
||||
|
||||
|
||||
class Mutation(ObjectType):
|
||||
search = Search.Field()
|
||||
|
|
|
|||
Loading…
Reference in a new issue