2014-09-05 3 views
0

모델의 여러 태그에 대한 좋은 해결책이나 해결책을 찾지 못했습니다.django-taggit 태그를 항상 소문자로 덮어 씁니다.

여기

How can I limit django-taggit to accept only lowercase words?

내 현재 코드는 다음과 같습니다 :

def clean_tags(self): 
    """ 
    Force all tags to lowercase. 
    """ 
    tags = self.cleaned_data.get('tags', None) 
    if tags: 
     tags = [t.lower() for t in tags] 

    return tags 

은 정말 따라 달라

from taggit.managers import TaggableManager 
from taggit.models import TaggedItemBase 


class TaggedStory(TaggedItemBase): 
    content_object = models.ForeignKey("Story") 


class TaggedSEO(TaggedItemBase): 
    content_object = models.ForeignKey("Story") 


class Story(models.Model): 
    ... 

    tags = TaggableManager(through=TaggedStory, blank=True, related_name='story_tags') 

    ... 

    seo_tags = TaggableManager(through=TaggedSEO, blank=True, related_name='seo_tags') 

답변

1

내가 일반적으로 폼 수준에서이를 구현 내가 가까이 볼 수있는 유일한 것은이 있었다 어떻게 보는지. 나는 그것을 검증 문제로 생각하기 때문에 해결책에 만족한다. 데이터 무결성 문제로 생각하면 모델 수준에서 왜 그렇게하고 싶은지 이해할 수 있습니다. 가장 좋은 방법은 Taggit 모듈을 Tag.save()를 재정의 할 수있는 지점으로 하위 클래스 화하는 것입니다.

+0

전화를 걸면 양식에서 확인하지 않은 것 같습니다. 나는 이것을 시도 할 수도있다, 나는 단지 그것을 서브 클래 싱하는 것에 대해 내 머리를 감쌀 수 없다. – John

+0

답변으로 받아 들여야합니다! –