# Path: characters/models.py
# class Character(models.Model):
# 
#     objects = CharacterManager()
# 
#     player = models.ForeignKey(User)
# 
#     name = models.CharField(max_length=200)
#     background = models.TextField()
# 
#     race = models.ForeignKey(Race)
#     # This name isn't ideal, but 'class' is a Python builtin, so here we are...
#     # I went with 'cclass' as short for 'character class'.
#     cclass = models.ForeignKey(Class, verbose_name="class")
# 
#     alignment = models.CharField(max_length=2, choices=Alignment.CHOICES,
#             default=Alignment.NEUTRAL)
# 
#     level = models.IntegerField(default=1)
#     experience_points = models.IntegerField(default=0)
# 
#     max_hit_points = models.IntegerField(default=10)
#     current_hit_points = models.IntegerField(default=10)
# 
#     strength = models.IntegerField(default=generate_stat)
#     dexterity = models.IntegerField(default=generate_stat)
#     constitution = models.IntegerField(default=generate_stat)
#     intelligence = models.IntegerField(default=generate_stat)
#     wisdom = models.IntegerField(default=generate_stat)
#     charisma = models.IntegerField(default=generate_stat)
# 
#     inventory = models.ManyToManyField(Item, null=True, blank=True)
# 
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     def __str__(self):
#         return self.name
# 
# class Race(models.Model):
# 
#     name = models.CharField('race', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Class(models.Model):
# 
#     name = models.CharField('class', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Classes"
# 
# class Item(models.Model):
# 
#     name = models.CharField(max_length=200)
#     description = models.TextField()
# 
#     value = models.IntegerField(default=0)
#     weight = models.IntegerField(default=1)
# 
#     def __str__(self):
#         return self.name


from django.contrib import admin
from characters.models import Character, Race, Class, Item


class CharacterAdmin(admin.ModelAdmin):

    list_display = ('name', 'level', 'race', 'cclass', 'player',
                    'created', 'modified')
    list_filter = ('cclass__name', 'race__name', 'created', 'modified')

    search_fields = ['name', 'background', 'race__name', 'cclass__name',
                     'player__username']

    readonly_fields = ('created', 'modified')

    fieldsets = [
        (None, {'fields': ['player', 'name', 'level', 'race', 'cclass',
                           'background']}),
        ('Hit Points', {'fields': ['max_hit_points', 'current_hit_points']}),
        ('Stats', {'fields': ['strength', 'dexterity', 'constitution',
                              'intelligence', 'wisdom', 'charisma']}),
        (None, {'fields': ['experience_points', 'inventory']}),
        ('Date Information', {'fields': ['created', 'modified']}),
    ]


admin.site.register(Character, CharacterAdmin)

# Path: characters/models.py
# class Character(models.Model):
# 
#     objects = CharacterManager()
# 
#     player = models.ForeignKey(User)
# 
#     name = models.CharField(max_length=200)
#     background = models.TextField()
# 
#     race = models.ForeignKey(Race)
#     # This name isn't ideal, but 'class' is a Python builtin, so here we are...
#     # I went with 'cclass' as short for 'character class'.
#     cclass = models.ForeignKey(Class, verbose_name="class")
# 
#     alignment = models.CharField(max_length=2, choices=Alignment.CHOICES,
#             default=Alignment.NEUTRAL)
# 
#     level = models.IntegerField(default=1)
#     experience_points = models.IntegerField(default=0)
# 
#     max_hit_points = models.IntegerField(default=10)
#     current_hit_points = models.IntegerField(default=10)
# 
#     strength = models.IntegerField(default=generate_stat)
#     dexterity = models.IntegerField(default=generate_stat)
#     constitution = models.IntegerField(default=generate_stat)
#     intelligence = models.IntegerField(default=generate_stat)
#     wisdom = models.IntegerField(default=generate_stat)
#     charisma = models.IntegerField(default=generate_stat)
# 
#     inventory = models.ManyToManyField(Item, null=True, blank=True)
# 
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     def __str__(self):
#         return self.name
# 
# class Race(models.Model):
# 
#     name = models.CharField('race', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Class(models.Model):
# 
#     name = models.CharField('class', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Classes"
# 
# class Item(models.Model):
# 
#     name = models.CharField(max_length=200)
#     description = models.TextField()
# 
#     value = models.IntegerField(default=0)
#     weight = models.IntegerField(default=1)
# 
#     def __str__(self):
#         return self.name


# Path: characters/admin.py
from django.contrib import admin
from characters.models import Character, Race, Class, Item



class CharacterAdmin(admin.ModelAdmin):

    list_display = ('name', 'level', 'race', 'cclass', 'player',
                    'created', 'modified')
    list_filter = ('cclass__name', 'race__name', 'created', 'modified')

    search_fields = ['name', 'background', 'race__name', 'cclass__name',
                     'player__username']

    readonly_fields = ('created', 'modified')

    fieldsets = [
        (None, {'fields': ['player', 'name', 'level', 'race', 'cclass',
                           'background']}),
        ('Hit Points', {'fields': ['max_hit_points', 'current_hit_points']}),
        ('Stats', {'fields': ['strength', 'dexterity', 'constitution',
                              'intelligence', 'wisdom', 'charisma']}),
        (None, {'fields': ['experience_points', 'inventory']}),
        ('Date Information', {'fields': ['created', 'modified']}),
    ]


admin.site.register(Character, CharacterAdmin)

admin.site.register(Race)