parent
d912bfcb8f
commit
5cd05de357
13 changed files with 289 additions and 49 deletions
@ -0,0 +1,51 @@ |
||||
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 TERMS, 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(TERMS)[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) |
||||
@ -0,0 +1,52 @@ |
||||
from generic_relations.relations import GenericRelatedField |
||||
from rest_framework.serializers import ModelSerializer, ImageField, FileField, SerializerMethodField, PrimaryKeyRelatedField, ReadOnlyField |
||||
|
||||
from .models import WorkSell, WorkSellPhoto |
||||
from common.serializers import LocationSerializer |
||||
from projects.serializers import BuildingClassficationSerializer, ConstructionTypeSerializer |
||||
from specializations.serializers import SpecializationSerializer |
||||
from users.serializers import UserSerializer |
||||
|
||||
|
||||
class WorkSellPhotoSerializer(ModelSerializer): |
||||
img = ImageField() |
||||
worksell_id = PrimaryKeyRelatedField(read_only=True, source='worksell') |
||||
|
||||
class Meta: |
||||
model = WorkSellPhoto |
||||
|
||||
fields = ( |
||||
'id', |
||||
'img', |
||||
'worksell_id', |
||||
) |
||||
|
||||
|
||||
class WorkSellSerializer(ModelSerializer): |
||||
building_classification = BuildingClassficationSerializer() |
||||
construction_type = ConstructionTypeSerializer() |
||||
contractor = UserSerializer() |
||||
id = ReadOnlyField() |
||||
location = LocationSerializer() |
||||
photos = WorkSellPhotoSerializer(many=True) |
||||
specialization = SpecializationSerializer() |
||||
|
||||
class Meta: |
||||
model = WorkSell |
||||
|
||||
fields = ( |
||||
'budget', |
||||
'building_classification', |
||||
'construction_type', |
||||
'contractor', |
||||
'created', |
||||
'currency', |
||||
'description', |
||||
'id', |
||||
'location', |
||||
'name', |
||||
'photos', |
||||
'specialization', |
||||
'term', |
||||
'term_type', |
||||
) |
||||
Loading…
Reference in new issue