def get_all_options(self): """ Returns all possible combinations of options for this products OptionGroups as a List of Lists. Ex: For OptionGroups Color and Size with Options (Blue, Green) and (Large, Small) you'll get [['Blue', 'Small'], ['Blue', 'Large'], ['Green', 'Small'], ['Green', 'Large']] Note: the actual values will be instances of Option instead of strings """ sublist = [] masterlist = [] #Create a list of all the options & create all combos of the options for opt in self.option_group.all(): for value in opt.option_set.all(): sublist.append(value) masterlist.append(sublist) sublist = [] return cross_list(masterlist)
def get_all_options(obj, ids_only=False): """ Returns all possible combinations of options for this products OptionGroups as a List of Lists. Ex: For OptionGroups Color and Size with Options (Blue, Green) and (Large, Small) you'll get [['Blue', 'Small'], ['Blue', 'Large'], ['Green', 'Small'], ['Green', 'Large']] Note: the actual values will be instances of Option instead of strings """ sublist = [] masterlist = [] #Create a list of all the options & create all combos of the options for opt in obj.option_group.select_related().all(): for value in opt.option_set.all(): if ids_only: sublist.append(value.unique_id) else: sublist.append(value) masterlist.append(sublist) sublist = [] results = cross_list(masterlist) return results