#-*- coding: utf-8 -*-

from django.db import models
from account.models import Member

class Forum(models.Model):
    name = models.CharField(max_length=100, verbose_name="Nom du forum")
    description = models.CharField(max_length=200, verbose_name="Description du forum")
    canAccess = []

    def __str__(self):
        return "Forum : {}".format(self.name)

class Topic(models.Model):
    title = models.CharField(max_length=100, verbose_name="Titre du topic")
    forum = models.ForeignKey(Forum)

    # TODO : solve problem of OneToOne relation combined to ForeignKey

    def __str__(self):
        return "Topic : {}".format(self.title)

class Message(models.Model):
    topic = models.ForeignKey(Topic)
    author = models.ForeignKey(Member, null=True)
    pseudo = models.CharField(max_length=50, verbose_name="Nom de l'invité", null=True)

    ip = models.GenericIPAddressField()
    
    date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date de création")
    m_date = models.DateTimeField(auto_now_add=False, auto_now=True, verbose_name="Dernière date de modification")

    content = models.TextField(null=True, blank=True)

    def __str__(self):
        return "Message : {}".format(self.content[0:50])