# 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)


from django.db import models
from django.core.urlresolvers import reverse_lazy
from apps.session.models import UserProfile
import re
# -*- coding: utf-8


class Grill(models.Model):
    title = models.CharField(max_length=80)
    created_time = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey(UserProfile)
    updated_time = models.DateTimeField(auto_now_add=True)
    content = models.TextField()

    def get_absolute_url(self):
        return reverse_lazy('view_grill', kwargs={'grill_id': self.id})


class GrillComment(models.Model):

    def save(self, *args, **kwargs):
        no = GrillComment.objects.filter(grill=self.grill).count()
        if no:
            self.order = no + 1
        else:
            self.order = 1
        super(GrillComment, self).save(*args, **kwargs)

    grill = models.ForeignKey(Grill)

# 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)


# Path: apps/grill/models.py
from django.db import models
from django.core.urlresolvers import reverse_lazy
from apps.session.models import UserProfile
import re

# -*- coding: utf-8


class Grill(models.Model):
    title = models.CharField(max_length=80)
    created_time = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey(UserProfile)
    updated_time = models.DateTimeField(auto_now_add=True)
    content = models.TextField()

    def get_absolute_url(self):
        return reverse_lazy('view_grill', kwargs={'grill_id': self.id})


class GrillComment(models.Model):

    def save(self, *args, **kwargs):
        no = GrillComment.objects.filter(grill=self.grill).count()
        if no:
            self.order = no + 1
        else:
            self.order = 1
        super(GrillComment, self).save(*args, **kwargs)

    grill = models.ForeignKey(Grill)

    author = models.ForeignKey(UserProfile)