def create_coffee(coffee): # skip duplicates if Coffee.objects.filter(name=coffee.name).count() > 0: messages.warning(req, 'Skipped "%s" since a coffee with that name already exists' % coffee.name) return c = Coffee() c.name = coffee.name c.description = coffee.description c.one_pound_price = coffee.one_pound_price c.two_pound_price = coffee.two_pound_price c.five_pound_price = coffee.five_pound_price c.set_image(coffee.image_data) c.save()