You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.9 KiB
52 lines
1.9 KiB
from django.contrib.auth.models import Group, Permission
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.core.management import BaseCommand
|
|
from django.utils import timezone
|
|
import pydash as _; _.map = _.map_; _.filter = _.filter_
|
|
import random
|
|
|
|
from archilance import util
|
|
from specializations.models import Specialization
|
|
from users.models import User
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
print('---------------------------------------')
|
|
print('Generating users...')
|
|
print('---------------------------------------')
|
|
|
|
|
|
User.objects.create_superuser('admin@example.com', '123456')
|
|
|
|
contractor_group = Group.objects.create(name='Исполнители')
|
|
customer_group = Group.objects.create(name='Заказчики')
|
|
|
|
# ct_proj = ContentType.objects.get_for_model(Project)
|
|
# ct_spec = ContentType.objects.get_for_model(Specialization)
|
|
# ct_register = ContentType.objects.get_for_model(RegistrationProfile)
|
|
#
|
|
#
|
|
# proj_perms = Permission.objects.filter(content_type=ct_proj)
|
|
# spec_perms = Permission.objects.filter(content_type=ct_spec)
|
|
# ct_register = Permission.objects.filter(content_type=ct_register)
|
|
#
|
|
# contractor_group.permissions.add(spec_perms, ct_register)
|
|
# customer_group.permissions.add(proj_perms, spec_perms, ct_register)
|
|
|
|
|
|
def create_user(i):
|
|
username = 'user-%s' % i
|
|
|
|
return User.objects.create(
|
|
first_name='User-%s' % i,
|
|
email='%s@example.com' % username,
|
|
is_active=True,
|
|
)
|
|
|
|
users = _.times(create_user, 50)
|
|
|
|
for user in users:
|
|
user.set_password('123')
|
|
user.groups.add(customer_group if user.pk % 2 == 0 else contractor_group)
|
|
user.save()
|
|
|