from django.db import models
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
from django.conf import settings
from django.contrib.auth.models import User
#This code is triggered whenever a new user has been created and saved to the database

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)

# Create your models here.
class TaskAll(models.Model):
    ACTIVE = 1
    FINISHED = 0
    STATUS = (
        (ACTIVE, ('Active')),
        (FINISHED, ('Finished')),
    )

    user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
    task = models.CharField(max_length=120)
    created = models.DateField(auto_now=True)
    finished = models.DateField(null=True)
    status = models.IntegerField(choices=STATUS, default=1)
    class Meta:
        ordering = ('created',)