How to use update_model method in localstack

Best Python code snippet using localstack_python

models.py

Source:models.py Github

copy

Full Screen

1# Import Django modules2from django.db import models3from django.utils import timezone4from django.core.exceptions import ValidationError5class HomeTypeModel(models.Model):6 """7 Class stores all the different homes types8 This generates the multiple select field in the survey9 If another home gets added it needs to be added here in the HOME_TYPE10 """11 APARTMENT = "ap"12 SINGLE_FAMILY = "sf"13 CONDO = "cn"14 OTHER = "ot"15 HOME_TYPE = (16 (APARTMENT, 'Apartment'),17 (SINGLE_FAMILY, 'Single Family'),18 (CONDO, 'Condo'),19 (OTHER, 'Other'),20 )21 home_type = models.CharField(22 unique=True,23 choices=HOME_TYPE,24 max_length=200,25 )26 def __str__(self):27 return self.home_type28class HomeProviderModel(models.Model):29 """30 Class stores all the different providers that are used31 """32 MLSPIN = "MLSPIN"33 YGL = "YGL"34 PROVIDER_TYPES = (35 (MLSPIN, 'MLSPIN'),36 (YGL, 'YGL'),37 )38 provider = models.CharField(39 unique=True,40 choices=PROVIDER_TYPES,41 max_length=200,42 )43 last_updated_feed = models.DateField(default=timezone.now)44 def __str__(self):45 return self.provider46 def save(self, *args, **kwargs):47 # Protect against multiple providers added via admin / command-line48 for provider in HomeProviderModel.objects.filter(provider=self.provider):49 if provider.pk is not self.pk:50 raise ValidationError("There should only be one {0} management object".format(self.provider))51 return super(HomeProviderModel, self).save(*args, **kwargs)52# This is used as a "hack" so that every abstract model class has a base class that contains53# the update function. This way when the chain of super's is done being called, it will call54# into this base class which will prevent the super function from breaking55class UpdateBase:56 def update(self, update_model):57 pass58class HouseLocationInformationModel(UpdateBase, models.Model):59 """60 Stores information regarding the location of the house61 """62 apartment_number = models.CharField(max_length=200, default="", blank=True)63 street_address = models.CharField(max_length=200)64 city = models.CharField(max_length=200)65 state = models.CharField(max_length=200)66 zip_code = models.CharField(max_length=200)67 latitude = models.DecimalField(max_digits=9, decimal_places=6, default=0)68 longitude = models.DecimalField(max_digits=9, decimal_places=6, default=0)69 @property70 def full_address(self):71 return self.street_address + ", " + self.city + ", " \72 + self.state + " " + self.zip_code73 def update(self, update_model):74 """75 Given another model, updates current model with fields from the new model76 :param update_model: (HouseLocationInformationModel) -> The model to use to update current model77 """78 super(HouseLocationInformationModel, self).update(update_model)79 self.apartment_number = update_model.apartment_number80 self.street_address = update_model.street_address81 self.city = update_model.city82 self.state = update_model.state83 self.zip_code = update_model.zip_code84 self.latitude = update_model.latitude85 self.longitude = update_model.longitude86 class Meta:87 abstract = True88class HouseInteriorAmenitiesModel(UpdateBase, models.Model):89 """90 Stores information about interior amenities91 """92 num_bathrooms = models.IntegerField(default=0)93 num_bedrooms = models.IntegerField(default=0)94 furnished = models.BooleanField(default=False)95 hardwood_floors = models.BooleanField(default=False)96 air_conditioning = models.BooleanField(default=False)97 dogs_allowed = models.BooleanField(default=False)98 cats_allowed = models.BooleanField(default=False)99 laundry_in_unit = models.BooleanField(default=False)100 dishwasher = models.BooleanField(default=False)101 def update(self, update_model):102 """103 Given another model, updates current model with fields from the new model104 :param update_model: (HouseInteriorAmenitiesModel) -> The model to use to update current model105 """106 super(HouseInteriorAmenitiesModel, self).update(update_model)107 self.num_bathrooms = update_model.num_bathrooms108 self.num_bedrooms = update_model.num_bedrooms109 self.furnished = update_model.furnished110 self.hardwood_floors = update_model.hardwood_floors111 self.air_conditioning = update_model.air_conditioning112 self.dogs_allowed = update_model.dogs_allowed113 self.cats_allowed = update_model.cats_allowed114 self.laundry_in_unit = update_model.laundry_in_unit115 self.dishwasher = update_model.dishwasher116 class Meta:117 abstract = True118class HouseExteriorAmenitiesModel(UpdateBase, models.Model):119 """120 Contains all the information for homes about the Exterior Amenities121 """122 parking_spot = models.BooleanField(default=False)123 pool = models.BooleanField(default=False)124 patio_balcony = models.BooleanField(default=False)125 gym = models.BooleanField(default=False)126 storage = models.BooleanField(default=False)127 laundry_in_building = models.BooleanField(default=False)128 def update(self, update_model):129 """130 Given another model, updates current model with fields from the new model131 :param update_model: (HouseExteriorAmenitiesModel) -> The model to use to update current model132 """133 super(HouseExteriorAmenitiesModel, self).update(update_model)134 self.parking_spot = update_model.parking_spot135 self.pool = update_model.pool136 self.patio_balcony = update_model.patio_balcony137 self.gym = update_model.gym138 self.storage = update_model.storage139 self.laundry_in_building = update_model.laundry_in_building140 class Meta:141 abstract = True142class HouseNearbyAmenitiesModel(UpdateBase, models.Model):143 """144 Contains all the nearby amenities associated with the home145 """146 laundromat_nearby = models.BooleanField(default=False)147 def update(self, update_model):148 """149 Given another model, updates current model with fields from the new model150 :param update_model: (HouseNearbyAmenitiesModel) -> The model to use to update current model151 """152 super(HouseNearbyAmenitiesModel, self).update(update_model)153 self.laundromat_nearby = update_model.laundromat_nearby154 class Meta:155 abstract = True156class HouseManagementModel(UpdateBase, models.Model):157 """158 Contains all the data related to managing the house listing159 """160 remarks = models.TextField(default="", blank=True)161 listing_number = models.IntegerField(default=-1) # The id of the home162 listing_provider = models.ForeignKey(HomeProviderModel)163 listing_agent = models.CharField(max_length=200, default="", blank=True)164 listing_agent_phone = models.CharField(max_length=200, default="", blank=True)165 listing_office = models.CharField(max_length=200, default="", blank=True) # The listing office, i.e William Raveis166 showing_instructions = models.TextField(default="", blank=True)167 showing_remarks = models.TextField(default="", blank=True)168 last_updated = models.DateField(default=timezone.now)169 def update(self, update_model):170 """171 Given another model, updates current model with fields from the new model172 :param update_model: (HouseManagementModel) -> The model to use to update current model173 """174 super(HouseManagementModel, self).update(update_model)175 self.remarks = update_model.remarks176 self.listing_number = update_model.listing_number177 self.listing_provider = update_model.listing_provider178 self.listing_agent = update_model.listing_agent179 self.listing_office = update_model.listing_office180 self.last_updated = update_model.last_updated181 class Meta:182 abstract = True183class RentDatabaseModel(HouseManagementModel, HouseExteriorAmenitiesModel, HouseLocationInformationModel,184 HouseInteriorAmenitiesModel, HouseNearbyAmenitiesModel):185 """186 This model stores all the information associated with a home187 """188 price = models.IntegerField(default=-1)189 home_type = models.ForeignKey('HomeTypeModel', on_delete=models.PROTECT)190 currently_available = models.BooleanField(default=False)191 date_available = models.DateField(default=timezone.now)192 def __str__(self):193 return self.full_address194 def update(self, update_model):195 """196 Given another model, updates current model with fields from the new model197 Calls into all its inherited classes to update the corresponding fields198 :param update_model: (RentDatabaseModel) -> The model to use to update current model199 """200 super(RentDatabaseModel, self).update(update_model)201 self.price = update_model.price202 self.home_type = update_model.home_type203 self.currently_available = update_model.currently_available204 self.date_available = update_model.date_available205 @property206 def price_string(self):207 return "$" + str(self.price)208 @property209 def on_market(self):210 """211 Returns whether or not the home is on market212 :return: (boolean) -> True: The home is currently on the market213 False: The home is not on the market214 """215 # As long as the date of when the feed was updated matches the data216 # that the home was last updated, then the home is on market217 if self.listing_provider.last_updated_feed != self.last_updated:218 return False219 else:220 return True221 @staticmethod222 def create_house_database(home_type=None, listing_provider=None, currently_available=False,223 price=1500, num_bedrooms=2, street_address="12 test Rd", city='SomeCity',224 zip_code='02222', state='MA'):225 if home_type is None:226 home_type = HomeTypeModel.objects.get_or_create(home_type=HomeTypeModel.APARTMENT)[0]227 if listing_provider is None:228 listing_provider = HomeProviderModel.objects.get_or_create(provider=HomeProviderModel.MLSPIN)[0]229 return RentDatabaseModel.objects.create(230 home_type=home_type,231 listing_provider=listing_provider,232 currently_available=currently_available,233 price=price,234 num_bedrooms=num_bedrooms,235 street_address=street_address,236 city=city,237 zip_code=zip_code,238 state=state,239 )240def house_directory_path(instance, filename):241 return 'houseDatabase/{0}/{1}'.format(instance.house.id, filename)242class HousePhotos(models.Model):243 house = models.ForeignKey('RentDatabaseModel', related_name='images', on_delete=models.CASCADE)244 image = models.ImageField(upload_to=house_directory_path)245 def __str__(self):...

Full Screen

Full Screen

rebalancing_signal_request.py

Source:rebalancing_signal_request.py Github

copy

Full Screen

...75 if self._configuration.client_side_validation and end_date is None:76 raise ValueError("Invalid value for `end_date`, must not be `None`") # noqa: E50177 self._end_date = end_date78 @property79 def update_model(self):80 """Gets the update_model of this RebalancingSignalRequest. # noqa: E50181 :return: The update_model of this RebalancingSignalRequest. # noqa: E50182 :rtype: bool83 """84 return self._update_model85 @update_model.setter86 def update_model(self, update_model):87 """Sets the update_model of this RebalancingSignalRequest.88 :param update_model: The update_model of this RebalancingSignalRequest. # noqa: E50189 :type: bool90 """91 self._update_model = update_model92 @property93 def model_id(self):94 """Gets the model_id of this RebalancingSignalRequest. # noqa: E50195 :return: The model_id of this RebalancingSignalRequest. # noqa: E50196 :rtype: str97 """98 return self._model_id99 @model_id.setter100 def model_id(self, model_id):...

Full Screen

Full Screen

updatesde.py

Source:updatesde.py Github

copy

Full Screen

...12 def handle(self, *args, **options):13 # Get cursor for sde db14 with connections['sde'].cursor() as cursor:15 updater = ModelUpdater(cursor)16 updater.update_model(MarketGroup, "invMarketGroups")17 updater.update_model(Category, "invCategories")18 updater.update_model(Group, "invGroups")19 updater.update_model(Type, "invTypes")20 updater.update_model(AttributeCategory, "dgmAttributeCategories")21 updater.update_model(AttributeType, "dgmAttributeTypes")22 updater.update_model(TypeAttribute, "dgmTypeAttributes", no_key=True)23 updater.update_model(Region, "mapRegions")24 updater.update_model(Constellation, "mapConstellations")25 updater.update_model(System, "mapSolarSystems") ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful