# Path: apps/session/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User,
#                                 primary_key=True, related_name='userprofile')
#     user = models.OneToOneField(User)
#     gender = models.CharField(max_length=1, choices=GENDER, default=ETC)
#     birthday = models.DateTimeField(blank=True, null=True)
# 
#     nickname = models.TextField(max_length=12)
#     points = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "User %s (%s)'s profile object" % (self.user, self.nickname)
# 
# class Message(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile', related_name='message_sent')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
#     is_read = models.BooleanField()
# 
#     def __str__(self):
#         return "Message from %s to %s at %s" % \
#             (self.sender, self.receiver, self.created_time)
# 
#     def read(self):
#         self.is_read = True
#         self.save()
# 
# class GroupMessage(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile',
#                                related_name='group_message_sent')
#     receivers = models.ForeignKey('Group',
#                                   related_name='group_message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return "Group Message from %s to %s at %s" % \
#             (self.sender, self.receivers, self.created_time)
# 
# class Block(models.Model):
#     sender = models.ForeignKey('UserProfile',
#                                related_name='block_message_from')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='block_message_to')
# 
#     def __str__(self):
#         return "%s blocked message from %s" % (self.receiver, self.sender)
# 
# class Group(models.Model):
#     members = models.ManyToManyField(UserProfile, related_name="groups")
#     name = models.CharField(max_length=30)
# 
#     # second argument(userprofile) can be one object or list of objects
#     def add_member(self, userprofile):
#         self.members.add(userprofile)
#         self.save()
# 
#     def remove_member(self, userprofile):
#         self.members.remove(userprofile)
#         self.save()


from django.contrib import admin
from apps.session.models import UserProfile, Message,\
    GroupMessage, Block, Group


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'nickname', 'points')


class MessageAdmin(admin.ModelAdmin):
    list_display = ('content', 'sender', 'receiver')


class GroupMessageAdmin(admin.ModelAdmin):
    list_display = ('content', 'sender', 'receivers', 'created_time')


class BlockAdmin(admin.ModelAdmin):
    list_display = ('sender', 'receiver')


class GroupAdmin(admin.ModelAdmin):
    list_display = ('members_list', 'name')

    def members_list(self, obj):

# Path: apps/session/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User,
#                                 primary_key=True, related_name='userprofile')
#     user = models.OneToOneField(User)
#     gender = models.CharField(max_length=1, choices=GENDER, default=ETC)
#     birthday = models.DateTimeField(blank=True, null=True)
# 
#     nickname = models.TextField(max_length=12)
#     points = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "User %s (%s)'s profile object" % (self.user, self.nickname)
# 
# class Message(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile', related_name='message_sent')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
#     is_read = models.BooleanField()
# 
#     def __str__(self):
#         return "Message from %s to %s at %s" % \
#             (self.sender, self.receiver, self.created_time)
# 
#     def read(self):
#         self.is_read = True
#         self.save()
# 
# class GroupMessage(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile',
#                                related_name='group_message_sent')
#     receivers = models.ForeignKey('Group',
#                                   related_name='group_message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return "Group Message from %s to %s at %s" % \
#             (self.sender, self.receivers, self.created_time)
# 
# class Block(models.Model):
#     sender = models.ForeignKey('UserProfile',
#                                related_name='block_message_from')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='block_message_to')
# 
#     def __str__(self):
#         return "%s blocked message from %s" % (self.receiver, self.sender)
# 
# class Group(models.Model):
#     members = models.ManyToManyField(UserProfile, related_name="groups")
#     name = models.CharField(max_length=30)
# 
#     # second argument(userprofile) can be one object or list of objects
#     def add_member(self, userprofile):
#         self.members.add(userprofile)
#         self.save()
# 
#     def remove_member(self, userprofile):
#         self.members.remove(userprofile)
#         self.save()


# Path: apps/session/admin.py
from django.contrib import admin
from apps.session.models import UserProfile, Message,\
    GroupMessage, Block, Group



class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'nickname', 'points')


class MessageAdmin(admin.ModelAdmin):
    list_display = ('content', 'sender', 'receiver')


class GroupMessageAdmin(admin.ModelAdmin):
    list_display = ('content', 'sender', 'receivers', 'created_time')


class BlockAdmin(admin.ModelAdmin):
    list_display = ('sender', 'receiver')


class GroupAdmin(admin.ModelAdmin):
    list_display = ('members_list', 'name')

    def members_list(self, obj):

        return ", ".join([str(user) for user in obj.members.all()])