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.
51 lines
2.1 KiB
51 lines
2.1 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 common.models import Location
|
|
from projects.models import TERM_TYPES, CURRENCIES, BuildingClassfication, ConstructionType
|
|
from specializations.models import Specialization
|
|
from users.models import User
|
|
from work_sell.models import WorkSell, WorkSellPhoto
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
print('---------------------------------------')
|
|
print('Generating work sells...')
|
|
print('---------------------------------------')
|
|
|
|
def create_work_sell(i):
|
|
ws = WorkSell(
|
|
budget=util.random_amount(),
|
|
created=util.random_date(),
|
|
currency=_.sample(CURRENCIES)[0],
|
|
description=util.lorem(),
|
|
name=util.lorem(words=_.random(2, 20), sentences=1),
|
|
term=_.random(0, 20),
|
|
term_type=_.sample(TERM_TYPES)[0],
|
|
)
|
|
|
|
ws.save()
|
|
|
|
ws.user = User.contractor_objects.order_by('?').first()
|
|
ws.building_classification = BuildingClassfication.objects.order_by('?').first()
|
|
ws.construction_type = ConstructionType.objects.order_by('?').first()
|
|
ws.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first()
|
|
ws.specialization = Specialization.objects.root_nodes()[0].get_descendants().order_by('?').first()
|
|
|
|
pic_names = _.split('a.png b.png c.jpg d.png e.jpg f.png g.png h.jpg i.png j.png k.jpg l.png m.png n.png o.png p.png q.jpg', ' ')
|
|
|
|
_.times(
|
|
lambda i_: ws.photos.create(img='_sample_files/%s' % util.take_one_random(pic_names)),
|
|
_.random(1, 15),
|
|
)
|
|
|
|
ws.save()
|
|
return ws
|
|
|
|
_.times(create_work_sell, 1000)
|
|
|