# Path: account/models.py
# class Account(models.Model):
#     user = models.ForeignKey(to='auth.User', related_name='accounts')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     @property
#     def user_avatar(self):
#         fs = FileSystemStorage()
#         if fs.exists(self.user.username + '.jpg'):
#             return '/static/avatar/' + self.user.username + '.jpg'
#         else:
#             return '/static/img/profile/default.jpg'
# 
#     def is_following(self, follow):
#         return self.following.filter(follow=follow).exists()
# 
#     def unfollow(self, follow):
#         relationship = self.following.filter(follow=follow).first()
#         relationship.delete()
# 
#     @staticmethod
#     def get_by_user(user):
#         return Account.objects.filter(user=user).first()
# 
#     @staticmethod
#     def get_by_username(username):
#         return Account.objects.filter(user__username=username).first()
# 
# class Relationship(models.Model):
#     owner = models.ForeignKey(to='account.Account', related_name='following')
#     follow = models.ForeignKey(to='account.Account', related_name='followers')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         unique_together = ('owner', 'follow',)


import factory
from django.contrib.auth.models import User
from account.models import Account, Relationship



DEFAULT_PASSWORD = 'abc@123'


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = User

    username = factory.sequence(lambda n: 'user{}'.format(n))
    email = factory.lazy_attribute(lambda n: '{}@test.com'.format(n.username.lower()))
    password = factory.PostGenerationMethodCall('set_password', DEFAULT_PASSWORD)
    first_name = factory.sequence(lambda n: 'First User Name {}'.format(n))
    last_name = factory.sequence(lambda n: 'Last User Name {}'.format(n))


class AccountFactory(factory.DjangoModelFactory):
    class Meta:
        model = Account

    user = factory.SubFactory(UserFactory)


class RelationshipFactory(factory.DjangoModelFactory):
    class Meta:

# Path: account/models.py
# class Account(models.Model):
#     user = models.ForeignKey(to='auth.User', related_name='accounts')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     @property
#     def user_avatar(self):
#         fs = FileSystemStorage()
#         if fs.exists(self.user.username + '.jpg'):
#             return '/static/avatar/' + self.user.username + '.jpg'
#         else:
#             return '/static/img/profile/default.jpg'
# 
#     def is_following(self, follow):
#         return self.following.filter(follow=follow).exists()
# 
#     def unfollow(self, follow):
#         relationship = self.following.filter(follow=follow).first()
#         relationship.delete()
# 
#     @staticmethod
#     def get_by_user(user):
#         return Account.objects.filter(user=user).first()
# 
#     @staticmethod
#     def get_by_username(username):
#         return Account.objects.filter(user__username=username).first()
# 
# class Relationship(models.Model):
#     owner = models.ForeignKey(to='account.Account', related_name='following')
#     follow = models.ForeignKey(to='account.Account', related_name='followers')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         unique_together = ('owner', 'follow',)


# Path: account/factories.py
import factory
from django.contrib.auth.models import User
from account.models import Account, Relationship




DEFAULT_PASSWORD = 'abc@123'


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = User

    username = factory.sequence(lambda n: 'user{}'.format(n))
    email = factory.lazy_attribute(lambda n: '{}@test.com'.format(n.username.lower()))
    password = factory.PostGenerationMethodCall('set_password', DEFAULT_PASSWORD)
    first_name = factory.sequence(lambda n: 'First User Name {}'.format(n))
    last_name = factory.sequence(lambda n: 'Last User Name {}'.format(n))


class AccountFactory(factory.DjangoModelFactory):
    class Meta:
        model = Account

    user = factory.SubFactory(UserFactory)


class RelationshipFactory(factory.DjangoModelFactory):
    class Meta:

        model = Relationship