individual models for each tagged field in Product

This commit is contained in:
Sam
2021-02-25 11:17:35 +00:00
parent 8ea0f74b8c
commit db55de0cf5
6 changed files with 41 additions and 24 deletions

View File

@@ -2,11 +2,34 @@ from django.contrib.gis.db import models
from tagulous.models import SingleTagField, TagField, TagTreeModel
from core.models import TreeTag
from companies.models import Company
# Create your models here.
class TreeTag(TagTreeModel):
class TagMeta:
initial = ""
force_lowercase = True
max_count=20
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
class CategoryTag(TagTreeModel):
class TagMeta:
initial = ""
force_lowercase = True
max_count=20
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
class AttributeTag(TagTreeModel):
class TagMeta:
initial = ""
force_lowercase = True
max_count=20
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
class Product(models.Model):
@@ -35,8 +58,8 @@ class Product(models.Model):
discount = models.DecimalField('Descuento', max_digits=5, decimal_places=2, null=True, blank=True)
stock = models.PositiveIntegerField('Stock', null=True, blank=True)
tags = TagField(to=TreeTag)
category = SingleTagField(null=True, blank=True) # main tag category
attributes = TagField(to=TreeTag, related_name='product_attributes')
category = SingleTagField(to=CategoryTag, null=True, blank=True) # main tag category
attributes = TagField(to=AttributeTag, related_name='product_attributes')
identifiers = models.TextField('Identificador único de producto', null=True, blank=True)
# internal

View File

@@ -318,7 +318,7 @@ class ProductViewSetTest(APITestCase):
'discount': '0.05',
'stock': 22,
'tags': ['tag1x, tag2x'],
'category': 'MayorTagCategory2',
'category': 'mayortagcategory2',
'attributes': ['color/blue', 'size/m'],
'identifiers': '34rf34f43c43',
}