# Path: channels/models.py
# class Channel(models.Model):
#     name = models.CharField(max_length=64, unique=True)
# 
#     STATUS_ACTIVE = 'AC'
#     STATUS_DELETED = 'DL'
# 
#     STATUS_CHOICES = (
#         (STATUS_ACTIVE, 'Active'),
#         (STATUS_DELETED, 'Deleted'),
#     )
# 
#     status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=STATUS_ACTIVE)
#     subscribers = models.ManyToManyField('auth.user', related_name="subscriptions")
#     members = models.ManyToManyField('auth.user', related_name="members")
# 
#     def get_absolute_url(self):
#         return reverse("view_channel", kwargs={"slug": self.name}) 
# 
#     def clean(self):
#         if len(self.name) < 2:
#             raise ValidationError('Name is to short (<2 Chars)')
# 
#         if not re.match(r'^\w+$', self.name):
#             raise ValidationError("Name must only contain letters, numbers and underscores.")


import datetime
from haystack import indexes
from channels.models import Channel


class ChannelIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True)
    name = indexes.CharField(model_attr='name')
    status = indexes.CharField(model_attr='status')

    def get_model(self):
        return Channel

    def prepare_text(self,obj):
    	return obj.name


# Path: channels/models.py
# class Channel(models.Model):
#     name = models.CharField(max_length=64, unique=True)
# 
#     STATUS_ACTIVE = 'AC'
#     STATUS_DELETED = 'DL'
# 
#     STATUS_CHOICES = (
#         (STATUS_ACTIVE, 'Active'),
#         (STATUS_DELETED, 'Deleted'),
#     )
# 
#     status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=STATUS_ACTIVE)
#     subscribers = models.ManyToManyField('auth.user', related_name="subscriptions")
#     members = models.ManyToManyField('auth.user', related_name="members")
# 
#     def get_absolute_url(self):
#         return reverse("view_channel", kwargs={"slug": self.name}) 
# 
#     def clean(self):
#         if len(self.name) < 2:
#             raise ValidationError('Name is to short (<2 Chars)')
# 
#         if not re.match(r'^\w+$', self.name):
#             raise ValidationError("Name must only contain letters, numbers and underscores.")


# Path: channels/search_indexes.py
import datetime
from haystack import indexes
from channels.models import Channel



class ChannelIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True)
    name = indexes.CharField(model_attr='name')
    status = indexes.CharField(model_attr='status')

    def get_model(self):
        return Channel

    def prepare_text(self,obj):
    	return obj.name


    def index_queryset(self, using=None):