From 6eaaf50ac54153362d1b9ef89299dbf801f859c5 Mon Sep 17 00:00:00 2001 From: b1ek Date: Fri, 5 May 2023 21:03:33 +1000 Subject: [PATCH] add apartment faker --- pairent_backend/pairent_app/factories.py | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 pairent_backend/pairent_app/factories.py diff --git a/pairent_backend/pairent_app/factories.py b/pairent_backend/pairent_app/factories.py new file mode 100644 index 0000000..416cc2e --- /dev/null +++ b/pairent_backend/pairent_app/factories.py @@ -0,0 +1,66 @@ +import factory +import factory.fuzzy + +from django.core.validators import RegexValidator + +import math + +import faker as fake_lib +from faker.providers import internet +faker = fake_lib.Factory.create('ru_RU'); + +from pairent_app.models import Apartament + +class ApartmentFactory(factory.django.DjangoModelFactory): + + class Meta: + model = Apartament + django_get_or_create = ('address',) + + # Base data + ipAddress = faker.ipv4_private(address_class='a') + price = faker.random.randint(2, 10) * 5000 + lastPrice = price + bail = faker.random.randint(1, 10) * 100 + + # agency comission is either 10% or 15% + agencyCommission = int(price / (10 + (faker.random.randint(0,1) * 5))) + utilitiesPrice = faker.random.randint(4, 16) * 1000 + minimumLeasePeriod = math.ceil(faker.random.randint(100,160) / 100) * 6 + + address = faker.address(); + description = ' '.join([faker.sentence() for i in range(5)]); + + perimetrs = faker.random.randint(150,400) / 10 + rooms = faker.random.randint(1, 4) # 0 - гостинка, 4 - трешка + ceilingHeight = faker.random.randint(5, 7) + floorHouse = faker.random.randint(2, 20) + floor = faker.random.randint(1, floorHouse) + + phoneNumberRegex = RegexValidator(regex = r"^\+?1?\d{8,15}$") + phoneNumber = faker.phone_number() + + timeToBus = faker.random.randint(2, 12) * 5 + timeToTrain = faker.random.randint(2, 12) * 5 + + # Apartment props + isFurniture = faker.random.randint(0, 1) + isAnimal = faker.random.randint(0, 1) + isTelevision = faker.random.randint(0, 1) + isChild = faker.random.randint(0, 1) + isInternet = faker.random.randint(0, 1) + isBathroom = faker.random.randint(0, 1) + isRefrigerator = faker.random.randint(0, 1) + isWasher = faker.random.randint(0, 1) + isAirConditioning = faker.random.randint(0, 1) + isFreshRepair = faker.random.randint(0, 1) + + # House props + isElevator = faker.random.randint(0, 1) + isParking = faker.random.randint(0, 1) + isGarbageChute = faker.random.randint(0, 1) + isConcierge = faker.random.randint(0, 1) + + views = faker.random.randint(10, 666) + + dateCreate = faker.date_between('-1y') \ No newline at end of file