def insert_car(customer_id, model, year, color, reg_number, manufacturer_id): Customer.push_to_embedded_list( customer_id, 'cars', { 'model': model, 'year': year, 'color': color, 'reg_number': reg_number, 'manufacturer_id': manufacturer_id, })
def insert_customer(name, phone_number, email, address, company_name): new_customer = Customer( { 'name': name, 'phone_number': phone_number, 'email': email, 'address': address, 'cars': [], 'orders': [], 'company_name': company_name } ) new_customer.save()
def change_customer_attribute(customer_id, attribute_name, new_value): try: Customer.change_attribute(customer_id, attribute_name, new_value) except ValueError: print('Incorrect argument entered')
def get_all_customers_by_attribute(attribute_name, value): try: return Customer.find(**{attribute_name: value}) except ValueError: print(f"The attribute_name; {attribute_name} was incorrect.")
def get_customer_by_id(customer_id): return Customer.find(_id=customer_id)
def get_all_customers(): return Customer.all()
def change_car_attribute(car, attribute_name, new_value): value = Customer.find(**{'cars': car})[0].cars value[0].update({attribute_name: new_value}) Customer.change_attribute( Customer.find(**{'cars': car})[0]._id, 'cars', value)
def get_all_cars_by_attribute(attribute_name, value): return [ attribute for car in Customer.all() for attribute in car.cars if attribute[attribute_name] == value ]
def get_all_cars(): car_list = [[car for car in customer.cars] for customer in Customer.all() if customer.cars] return [car for sub_list in car_list for car in sub_list]