import datetime

from django.db import models
from django.contrib.auth.models import User

app_name = 'main'

class Task_List(models.Model):
	class Meta:
		verbose_name = 'Task List'
		verbose_name_plural = 'Task Lists'
	name = models.CharField(max_length=200)
	owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
	created_at = models.DateTimeField('date created')
	def __str__(self):
		return self.name
	def to_json(self):
		return {
			'id': self.id,
			'name': self.name,
			'owner': self.owner.username if self.owner else None,
			'created_at': self.created_at
		}

class Task(models.Model):
	class Meta:
		verbose_name = 'Task'
		verbose_name_plural = 'Tasks'
	task_list = models.ForeignKey(Task_List, on_delete=models.CASCADE, related_name='tasks')
	name = models.CharField(max_length=200)
	created_at = models.DateTimeField('date created')
	due_on = models.DateTimeField('deadline')
	owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
	mark = models.BooleanField(default=False)