import datetime

import factory
from django.contrib.auth.models import User
from django.utils.text import slugify
from factory.django import DjangoModelFactory

from . import models


class WeekdayFactory(DjangoModelFactory):
    """Weekday model factory."""

    class Meta:
        model = models.Weekday

    name = 'Monday'
    slug = factory.LazyAttribute(lambda obj: '%s' % slugify(obj.name))


class MealFactory(DjangoModelFactory):
    """Meal model factory."""

    class Meta:
        model = models.Meal

    name = 'Breakfast'
    slug = factory.LazyAttribute(lambda obj: '%s' % slugify(obj.name))
    start_time = datetime.time(5, 7, 9)
    end_time = datetime.time(6, 7, 9)


class MealOptionFactory(DjangoModelFactory):
    """MealOption model factory."""

    class Meta:
        model = models.MealOption

    name = 'Option A'
    slug = factory.LazyAttribute(lambda obj: '%s' % slugify(obj.name))


class CourseFactory(DjangoModelFactory):
    """Course model factory."""

    class Meta:
        model = models.Course

    name = 'Appetizer'
    slug = factory.LazyAttribute(lambda obj: '%s' % slugify(obj.name))


# Continue from here
class UserFactory(DjangoModelFactory):
    class Meta:
        model = User

    name = "John Doe"


class AdminFactory(DjangoModelFactory):
    class Meta:
        model = models.Admin

    user = ''
    timetable = ''
    is_super = True


class TimetableFactory(DjangoModelFactory):
    """Timetable model factory."""

    class Meta:
        model = models.Timetable

    name = 'Fellows Timetable'
    slug = factory.LazyAttribute(lambda obj: '%s' % slugify(obj.name))
    code = 'FT7876'
    api_key = 'TF78993jTY'
    cycle_length = 14
    current_cycle_day = 2
    description = 'Some random description'
    admins = ''


#     admins = models.ManyToManyField(User, through='Admin')


# class Admin(models.Model):
#     """Model representing timetables' administratorship"""

#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE)
#     is_super = models.BooleanField()

@@ -53,23 +53,16 @@
 auth
-.models
  import 
 User
@@ -57,20 +57,30 @@
  import 
-User
+get_user_model
 %0Afrom dj
@@ -1135,29 +1135,8 @@
 )%0A%0A%0A
-# Continue from here%0A
 clas
@@ -1178,192 +1178,278 @@
     
-class Meta:%0A        model = User%0A%0A    name = %22John Doe%22%0A%0A%0Aclass AdminFactory(DjangoModelFactory):%0A    class Meta:%0A        model = models.Admin%0A%0A    user = ''%0A    timetable = ''
+%22%22%22Django admin user model factory.%22%22%22%0A%0A    class Meta:%0A        model = get_user_model()%0A        django_get_or_create = ('username', 'email', 'password')%0A%0A    username = 'admin'%0A    email = 'admin@admin.com'%0A    password = 'adminpassword'%0A    is_superuser = True
 %0A    is_
 supe
@@ -1444,21 +1444,22 @@
 %0A    is_
-super
+active
  = True%0A
@@ -1835,258 +1835,399 @@
 on'%0A
-    admins = ''%0A%0A%0A#     admins = models.ManyToManyField(User, through='Admin')%0A%0A%0A# class Admin(models.Model):%0A#     %22%22%22Model representing timetables' administratorship
+%0A%0Aclass AdminFactory(DjangoModelFactory):%0A    %22%22%22Admin model factory.%22%22%22%0A%0A    class Meta:%0A        model = models.Admin%0A%0A    user = factory.SubFactory(UserFactory)%0A    timetable = factory.SubFactory(TimetableFactory)%0A    is_super = True%0A%0A%0Aclass UserWithTimetableFactory(DjangoModelFactory):%0A    
 %22%22%22%0A
-%0A#
     
- user = models.ForeignKey(User, on_delete=models.CASCADE)%0A#     t
+Factory specifying many-to-many through relationship.%0A%0A    The 'admin' field in T
 imetable
  = m
@@ -2226,101 +2226,148 @@
 able
- =
  model
-s.ForeignKey(Timetable, on_delete=models.CASCADE)%0A#     is_super = models.BooleanField(
+ is a many-to-many relationship%0A    to User model through Admin model.%0A    %22%22%22%0A%0A    admins = factory.RelatedFactory(AdminFactory, 'user'
 )%0A

Create factories for django user, Admin and Timetable models.