fix faker
This commit is contained in:
parent
c6a4784cd2
commit
767ed3538a
|
@ -1,55 +1,84 @@
|
|||
import factory
|
||||
import random
|
||||
import time, datetime
|
||||
|
||||
from django.db import models
|
||||
|
||||
from pairent_app.models import Apartament
|
||||
|
||||
factory.Faker.override_default_locale('ru_RU');
|
||||
|
||||
class PhoneNumber(factory.declarations.BaseDeclaration):
|
||||
def evaluate(self, instance, step, extra):
|
||||
return '+799' + str(random.randint(0, 99999999)).zfill(8);
|
||||
|
||||
class Random(factory.declarations.BaseDeclaration):
|
||||
def __init__(self, min, max = None, multiply = 1):
|
||||
if (max == None):
|
||||
self.min = 0;
|
||||
self.max = min;
|
||||
else:
|
||||
self.min = min;
|
||||
self.max = max;
|
||||
self.multiply = multiply;
|
||||
super().__init__();
|
||||
|
||||
def evaluate(self, instance, step, extra):
|
||||
if (self.multiply != None):
|
||||
return random.randint(self.min, self.max) * self.multiply;
|
||||
return random.randint(self.min, self.max);
|
||||
|
||||
class Date(factory.declarations.BaseDeclaration):
|
||||
def evaluate(self, instance, step, extra):
|
||||
# year_before = time.time() - (60 * 60 * 24 * 30 * 12);
|
||||
return datetime.datetime(2023, random.randint(1,12), random.randint(1,27)).strftime("%G-%m-%d");
|
||||
|
||||
class ApartmentFactory(factory.django.DjangoModelFactory):
|
||||
|
||||
class Meta:
|
||||
model = Apartament
|
||||
|
||||
# Base data
|
||||
price = factory.Faker('random_number')
|
||||
lastPrice = price
|
||||
bail = factory.Faker('random_number')
|
||||
price = Random(3,10,5000);
|
||||
lastPrice = Random(3,10,5000);
|
||||
bail = Random(2,10,1000);
|
||||
|
||||
agencyCommission = factory.Faker('random_number')
|
||||
utilitiesPrice = factory.Faker('random_number')
|
||||
minimumLeasePeriod = factory.Faker('random_number')
|
||||
agencyCommission = Random(3,5,2500);
|
||||
utilitiesPrice = Random(4,8,1000)
|
||||
minimumLeasePeriod = Random(1,2,6);
|
||||
|
||||
address = factory.Faker('address')
|
||||
description = factory.Faker('sentence')
|
||||
address = factory.Faker('address', locale='ru_RU');
|
||||
description = factory.Faker('sentence', locale='ru_RU');
|
||||
|
||||
perimetrs = factory.Faker('random_number')
|
||||
rooms = factory.Faker('random_number')
|
||||
ceilingHeight = factory.Faker('random_number')
|
||||
floorHouse = factory.Faker('random_number')
|
||||
floor = factory.Faker('random_number')
|
||||
perimetrs = Random(15,40);
|
||||
rooms = Random(0,4);
|
||||
ceilingHeight = Random(3,5);
|
||||
floorHouse = Random(2,20);
|
||||
floor = Random(2,20);
|
||||
|
||||
phoneNumber = factory.Faker('phone_number')
|
||||
phoneNumber = PhoneNumber()
|
||||
|
||||
timeToBus = factory.Faker('random_number')
|
||||
timeToTrain = factory.Faker('random_number')
|
||||
timeToBus = Random(1, 12, 5);
|
||||
timeToTrain = Random(1, 12, 5);
|
||||
|
||||
# Apartment props
|
||||
isFurniture = factory.Faker('boolean')
|
||||
isAnimal = factory.Faker('boolean')
|
||||
isTelevision = factory.Faker('boolean')
|
||||
isChild = factory.Faker('boolean')
|
||||
isInternet = factory.Faker('boolean')
|
||||
isBathroom = factory.Faker('boolean')
|
||||
isRefrigerator = factory.Faker('boolean')
|
||||
isWasher = factory.Faker('boolean')
|
||||
isAirConditioning = factory.Faker('boolean')
|
||||
isFreshRepair = factory.Faker('boolean')
|
||||
isFurniture = Random(0, 1);
|
||||
isAnimal = Random(0, 1);
|
||||
isTelevision = Random(0, 1);
|
||||
isChild = Random(0, 1);
|
||||
isInternet = Random(0, 1);
|
||||
isBathroom = Random(0, 1);
|
||||
isRefrigerator = Random(0, 1);
|
||||
isWasher = Random(0, 1);
|
||||
isAirConditioning = Random(0, 1);
|
||||
isFreshRepair = Random(0, 1);
|
||||
|
||||
# House props
|
||||
isElevator = factory.Faker('boolean')
|
||||
isParking = factory.Faker('boolean')
|
||||
isGarbageChute = factory.Faker('boolean')
|
||||
isConcierge = factory.Faker('boolean')
|
||||
isElevator = Random(0, 1);
|
||||
isParking = Random(0, 1);
|
||||
isGarbageChute = Random(0, 1);
|
||||
isConcierge = Random(0, 1);
|
||||
|
||||
views = factory.Faker('random_number')
|
||||
# views = [] # factory.Faker('random_number')
|
||||
|
||||
dateCreate = factory.Faker('date')
|
||||
dateCreate = Date()
|
Loading…
Reference in New Issue