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

import uuid

from django.contrib.auth.models import AbstractUser
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token


class User(AbstractUser):

    class Meta(object):
        unique_together = ('email', )


class NoteBook(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    title = models.CharField(max_length=255)
    created_by = models.ForeignKey(User, related_name='notebooks')
    created_at = models.DateTimeField(auto_now_add=True)


class Note(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    title = models.CharField(max_length=255)
    starred = models.BooleanField(default=False)
    crypted = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User, related_name='notes')
    notebook = models.ForeignKey(NoteBook, related_name='notes')


class NoteRevision(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User)
    note = models.ForeignKey(Note, related_name='revisions')


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

@@ -274,17 +274,16 @@
 tUser):%0A
-%0A
     clas
@@ -337,16 +337,104 @@
 il', )%0A%0A
+User._meta.get_field('email').blank = False%0AUser._meta.get_field('email').null = False%0A%0A
 %0Aclass N

add null and blank option to False on email user field