# Path: challenges/models.py
# class Hint(models.Model):
#     challenge = models.ForeignKey('challenges.Challenge', related_name='hints', on_delete=models.CASCADE)
#     text = models.TextField()
# 
#     class Meta:
#         unique_together = ('challenge', 'text')
# 
#     def __str__(self):
#         return self.text
# 
# class Attachment(models.Model):
#     name = models.CharField(max_length=256)
#     challenge = models.ForeignKey('challenges.Challenge', related_name='attachments', on_delete=models.CASCADE)
#     description = models.TextField()
#     file = models.ImageField(upload_to='challenges')
# 
#     def __str__(self):
#         return self.name
# 
# class ChallengeSolved(models.Model):
#     user = models.ForeignKey(RelatedUserModel, on_delete=models.CASCADE)
#     challenge = models.ForeignKey('challenges.Challenge', on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return 'Challenge: {}, User: {}'.format(self.challenge.name, self.user)
# 
# class Challenge(models.Model):
#     objects = ChallengeQuerySet.as_manager()
# 
#     name = models.CharField(max_length=256)
#     category = models.ForeignKey('challenges.Category', related_name='challenges', on_delete=models.CASCADE)
#     description = models.TextField()
#     key = models.CharField(max_length=256)
#     points = models.IntegerField()
#     difficulty = models.CharField(max_length=1, choices=(
#         ('E', 'Easy'),
#         ('M', 'Medium'),
#         ('H', 'Hard')
#     ))
# 
#     solved_by = models.ManyToManyField(RelatedUserModel,
#                                        related_name='solved_challenges',
#                                        through='challenges.ChallengeSolved')
# 
#     failed_by = models.ManyToManyField(RelatedUserModel,
#                                        related_name='_all_failed_challenges',
#                                        through='challenges.ChallengeFail')
# 
#     @property
#     def newest_solved(self):
#         return self.challengesolved_set.order_by('-datetime')
# 
#     def __str__(self):
#         return self.name
# 
# class Category(models.Model):
#     name = models.CharField(max_length=256, unique=True)
#     description = models.TextField()
# 
#     class Meta:
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return self.name


from django.contrib import admin
from tinymce import TinyMCE
from challenges.models import Hint, Attachment, ChallengeSolved, Challenge, Category
from django import forms
class ChallengeAdminForm(forms.ModelForm):
    class Meta:
        model = Challenge
        widgets = {
           'description': TinyMCE(mce_attrs={'width': 800})
        }
        fields = '__all__'


class CategoryAdminForm(forms.ModelForm):
    class Meta:
        model = Category
        widgets = {
           'description': TinyMCE(mce_attrs={'width': 800})
        }
        fields = '__all__'


class HintAdmin(admin.TabularInline):
    model = Hint
    fieldsets = (None, {'fields': ('text',)}),
    can_delete = True


class AttachmentAdmin(admin.TabularInline):
    model = Attachment
    fieldsets = (None, {'fields': ('name', 'description', 'file')}),
    can_delete = True



# Path: challenges/models.py
# class Hint(models.Model):
#     challenge = models.ForeignKey('challenges.Challenge', related_name='hints', on_delete=models.CASCADE)
#     text = models.TextField()
# 
#     class Meta:
#         unique_together = ('challenge', 'text')
# 
#     def __str__(self):
#         return self.text
# 
# class Attachment(models.Model):
#     name = models.CharField(max_length=256)
#     challenge = models.ForeignKey('challenges.Challenge', related_name='attachments', on_delete=models.CASCADE)
#     description = models.TextField()
#     file = models.ImageField(upload_to='challenges')
# 
#     def __str__(self):
#         return self.name
# 
# class ChallengeSolved(models.Model):
#     user = models.ForeignKey(RelatedUserModel, on_delete=models.CASCADE)
#     challenge = models.ForeignKey('challenges.Challenge', on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return 'Challenge: {}, User: {}'.format(self.challenge.name, self.user)
# 
# class Challenge(models.Model):
#     objects = ChallengeQuerySet.as_manager()
# 
#     name = models.CharField(max_length=256)
#     category = models.ForeignKey('challenges.Category', related_name='challenges', on_delete=models.CASCADE)
#     description = models.TextField()
#     key = models.CharField(max_length=256)
#     points = models.IntegerField()
#     difficulty = models.CharField(max_length=1, choices=(
#         ('E', 'Easy'),
#         ('M', 'Medium'),
#         ('H', 'Hard')
#     ))
# 
#     solved_by = models.ManyToManyField(RelatedUserModel,
#                                        related_name='solved_challenges',
#                                        through='challenges.ChallengeSolved')
# 
#     failed_by = models.ManyToManyField(RelatedUserModel,
#                                        related_name='_all_failed_challenges',
#                                        through='challenges.ChallengeFail')
# 
#     @property
#     def newest_solved(self):
#         return self.challengesolved_set.order_by('-datetime')
# 
#     def __str__(self):
#         return self.name
# 
# class Category(models.Model):
#     name = models.CharField(max_length=256, unique=True)
#     description = models.TextField()
# 
#     class Meta:
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return self.name


# Path: challenges/admin.py
from django.contrib import admin
from tinymce import TinyMCE
from challenges.models import Hint, Attachment, ChallengeSolved, Challenge, Category
from django import forms

class ChallengeAdminForm(forms.ModelForm):
    class Meta:
        model = Challenge
        widgets = {
           'description': TinyMCE(mce_attrs={'width': 800})
        }
        fields = '__all__'


class CategoryAdminForm(forms.ModelForm):
    class Meta:
        model = Category
        widgets = {
           'description': TinyMCE(mce_attrs={'width': 800})
        }
        fields = '__all__'


class HintAdmin(admin.TabularInline):
    model = Hint
    fieldsets = (None, {'fields': ('text',)}),
    can_delete = True


class AttachmentAdmin(admin.TabularInline):
    model = Attachment
    fieldsets = (None, {'fields': ('name', 'description', 'file')}),
    can_delete = True



@admin.register(Challenge)