import datetime
from django.template.defaultfilters import slugify
from factory import DjangoModelFactory, lazy_attribute
from random import randint
from .models import Author
from .models import Book


class UserFactory(DjangoModelFactory):
    class Meta:
        model = 'auth.User'
        django_get_or_create = ('username',)

    first_name = 'John'
    last_name = 'Doe'
    username = lazy_attribute(
        lambda o: slugify(o.first_name + '.' + o.last_name)
    )
    email = lazy_attribute(lambda o: o.username + "@example.com")

    @lazy_attribute
    def date_joined(self):
        return datetime.datetime.now() - datetime.timedelta(
            days=randint(5, 50)
        )
    last_login = lazy_attribute(
        lambda o: o.date_joined + datetime.timedelta(days=4)
    )


class AuthorFactory(DjangoModelFactory):
    class Meta:
        model = Author
        django_get_or_create = ('name',)

    name = 'Noam Chomsky'


class BookFactory(DjangoModelFactory):
    class Meta:
        model = Book
        django_get_or_create = ('title',)

    title = 'Colorless Green Ideas Sleep Furiously'

import datetime
from django.template.defaultfilters import slugify
from factory import DjangoModelFactory, lazy_attribute
from random import randint


class UserFactory(DjangoModelFactory):
    class Meta:
        model = 'auth.User'
        django_get_or_create = ('username',)

    first_name = 'John'
    last_name = 'Doe'
    username = lazy_attribute(
        lambda o: slugify(o.first_name + '.' + o.last_name)
    )
    email = lazy_attribute(lambda o: o.username + "@example.com")

    @lazy_attribute
    def date_joined(self):
        return datetime.datetime.now() - datetime.timedelta(
            days=randint(5, 50)
        )
    last_login = lazy_attribute(
        lambda o: o.date_joined + datetime.timedelta(days=4)
    )

Revert "Add AuthorFactory and BookFactory."
Revert "Add AuthorFactory and BookFactory."

This reverts commit 8cde42f87a82206cf63b3a5e4b0ec6c38d66d3a7.

  import datetime
  from django.template.defaultfilters import slugify
  from factory import DjangoModelFactory, lazy_attribute
  from random import randint
- from .models import Author
- from .models import Book
  
  
  class UserFactory(DjangoModelFactory):
      class Meta:
          model = 'auth.User'
          django_get_or_create = ('username',)
  
      first_name = 'John'
      last_name = 'Doe'
      username = lazy_attribute(
          lambda o: slugify(o.first_name + '.' + o.last_name)
      )
      email = lazy_attribute(lambda o: o.username + "@example.com")
  
      @lazy_attribute
      def date_joined(self):
          return datetime.datetime.now() - datetime.timedelta(
              days=randint(5, 50)
          )
      last_login = lazy_attribute(
          lambda o: o.date_joined + datetime.timedelta(days=4)
      )
  
- 
- class AuthorFactory(DjangoModelFactory):
-     class Meta:
-         model = Author
-         django_get_or_create = ('name',)
- 
-     name = 'Noam Chomsky'
- 
- 
- class BookFactory(DjangoModelFactory):
-     class Meta:
-         model = Book
-         django_get_or_create = ('title',)
- 
-     title = 'Colorless Green Ideas Sleep Furiously'
- 
Revert "Add AuthorFactory and BookFactory."
## Code Before:
import datetime
from django.template.defaultfilters import slugify
from factory import DjangoModelFactory, lazy_attribute
from random import randint
from .models import Author
from .models import Book


class UserFactory(DjangoModelFactory):
    class Meta:
        model = 'auth.User'
        django_get_or_create = ('username',)

    first_name = 'John'
    last_name = 'Doe'
    username = lazy_attribute(
        lambda o: slugify(o.first_name + '.' + o.last_name)
    )
    email = lazy_attribute(lambda o: o.username + "@example.com")

    @lazy_attribute
    def date_joined(self):
        return datetime.datetime.now() - datetime.timedelta(
            days=randint(5, 50)
        )
    last_login = lazy_attribute(
        lambda o: o.date_joined + datetime.timedelta(days=4)
    )


class AuthorFactory(DjangoModelFactory):
    class Meta:
        model = Author
        django_get_or_create = ('name',)

    name = 'Noam Chomsky'


class BookFactory(DjangoModelFactory):
    class Meta:
        model = Book
        django_get_or_create = ('title',)

    title = 'Colorless Green Ideas Sleep Furiously'

## Instruction:
Revert "Add AuthorFactory and BookFactory."
## Code After:
import datetime
from django.template.defaultfilters import slugify
from factory import DjangoModelFactory, lazy_attribute
from random import randint


class UserFactory(DjangoModelFactory):
    class Meta:
        model = 'auth.User'
        django_get_or_create = ('username',)

    first_name = 'John'
    last_name = 'Doe'
    username = lazy_attribute(
        lambda o: slugify(o.first_name + '.' + o.last_name)
    )
    email = lazy_attribute(lambda o: o.username + "@example.com")

    @lazy_attribute
    def date_joined(self):
        return datetime.datetime.now() - datetime.timedelta(
            days=randint(5, 50)
        )
    last_login = lazy_attribute(
        lambda o: o.date_joined + datetime.timedelta(days=4)
    )
