Before we can define the domain service to add a room, we need to ensure that individual room types can be independently selected. This is accomplished by generating a unique room type key. We thus add a new method, generateRoomTypeKey(), to the booksomeplace.entity.property.RoomType class, as shown here:
def generateRoomTypeKey(self) :
import random
first4 = self['type']
first4 = first4.replace(' ', '')
first4 = first4[0:4]
first4 = first4.ljust(4, '_')
self['roomTypeKey'] = first4.upper() + \
str(random.randint(1000, 9999))
return self['roomTypeKey']
We are now in a position to add a saveRoom() method to PropertyService in the booksomeplace.domain.property module. This method adds the new RoomType to the embedded list in the properties collection. Note the use of the $push array operator:
...