2

I'm specifically talking about the Tag model, which I have no much experience with. The code goes like this:

@register_snippet
class ArticleTag(index.Indexed,Tag):

class Meta:
    proxy=True

search_fields = [
    index.SearchField('name', partial_match=True),
    index.SearchField('slug', partial_match=True),
]

The Tag model has two fields, 'name' and 'slug'. But now I want to add a third custom field named 'type' that will be simply a CharField.

I tried modifying it like this:

@register_snippet
class ArticleTag(index.Indexed,Tag):

class Meta:
    proxy=True

search_fields = [
    index.SearchField('name', partial_match=True),
    index.SearchField('slug', partial_match=True),
]

merge_to = models.CharField(max_length=500, blank=True, null=True)

panels = [
    FieldPanel('name'),
    FieldPanel('slug'),
    FieldPanel('type'),
]

However the server yields:

ERRORS:
?: (models.E017) Proxy model 'ArticleTag' contains model fields.

How can I achieve what I am trying to do?

Pablo Viacheslav
  • 873
  • 1
  • 8
  • 15

2 Answers2

0

Your tag gas to inherit from TagBase and you'll have to create a custom through model. The django-taggit documentation has an example on how to create custom tags.

Loïc Teixeira
  • 1,404
  • 9
  • 19
0

We can do this below trick :P

class Model(object):
    '''
    Skip extra field validation "models.E017"
    '''

    @classmethod
    def _check_model(cls):
        errors = []
        return errors

@register_snippet
class ArticleTag(Model, index.Indexed,Tag):
    class Meta:
        proxy=True

anjaneyulubatta505
  • 10,713
  • 1
  • 52
  • 62