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.
82 lines
2.4 KiB
82 lines
2.4 KiB
# from cms_pages.models import Menu, CmsPage
|
|
# from django.contrib import sites
|
|
# from django.core.files import File
|
|
# from django.db import connection
|
|
# from django.db.models import Q
|
|
# from pprint import pprint, pformat
|
|
# from wagtail.wagtailcore.models import Page
|
|
# import copy
|
|
# import eav.models
|
|
# import inspect
|
|
# import itertools
|
|
# import json
|
|
# import os
|
|
# import requests
|
|
# import util
|
|
from django.core.management import BaseCommand
|
|
from django.utils import timezone
|
|
import pydash as _; _.map = _.map_; _.filter = _.filter_
|
|
import random
|
|
from django.contrib.auth.models import Group
|
|
|
|
from users.models import User
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
print('---------------------------------------')
|
|
print('Generating data...')
|
|
print('---------------------------------------')
|
|
|
|
|
|
def take(coll, n):
|
|
chunk = coll[0:n]
|
|
del coll[0:n]
|
|
return chunk
|
|
|
|
def take_random(coll, n):
|
|
if n == 0:
|
|
return []
|
|
|
|
chunk = _.sample(coll, n)
|
|
|
|
for item in chunk:
|
|
coll.remove(item)
|
|
|
|
return chunk
|
|
|
|
def take_one_random(coll):
|
|
if len(coll) == 0:
|
|
return None
|
|
|
|
return coll.pop(_.random(0, len(coll)-1))
|
|
|
|
def random_phone():
|
|
return '+7' + str(_.sample((917, 964, 965, 987, 912, 935))) + str(_.random(1000000, 9999999))
|
|
|
|
def random_date():
|
|
return timezone.datetime(_.random(2012, 2018), _.random(1, 12), _.random(1, 28))
|
|
|
|
def random_amount():
|
|
return random.random() * random.choice((100, 1000, 10000))
|
|
|
|
|
|
User.objects.create_superuser('admin@example.com', '123456')
|
|
|
|
def create_user(i):
|
|
username = 'user-%s' % i
|
|
|
|
return User.objects.create(
|
|
first_name='User-%s' % i,
|
|
email='%s@example.com' % username,
|
|
is_active=_.sample((True, False)),
|
|
)
|
|
|
|
Group.objects.create(name='Исполнители')
|
|
Group.objects.create(name='Заказчики')
|
|
|
|
users = _.times(create_user, 50)
|
|
|
|
for user in users:
|
|
user.set_password('123')
|
|
user.save()
|
|
|