from django.db import models
from UserManage.models import User

class Contestants(models.Model):
	user = models.OneToOneField(User,related_name="contestant")

	def __unicode__(self):
		return self.user.name

class PhotoWorks(models.Model):
	author = models.ForeignKey(Contestants,related_name="works")
	uuid = models.CharField(max_length=36,db_index=True,unique=True)
	title = models.CharField(max_length=255,db_index=True)
	desc = models.TextField()
	filename = models.CharField(max_length=64,db_index=True)
	fileext = models.CharField(max_length=16)
	importid = models.IntegerField()
	score = models.IntegerField()

	def __unicode__(self):
		return "%s@%s"%(self.title,self.author.user.name)

class VoteRecords(models.Model):
	voter = models.OneToOneField(User,related_name="vtrec")
	target = models.ForeignKey(PhotoWorks,related_name="vrec")
	comment = models.TextField()
	time = models.DateTimeField(auto_now_add=True)

	def __unicode__(self):
		return "%s => %s@%s"%(self.voter.name,self.target.title,self.target.author.user.name)