for record in reader:
new_values = {
'product_code': slugify(record['Product Code']),
'msrp': record['Suggested Retail'],
#etc...
}
product, was_created = Product.objects.get_or_create(source_id = record['Source ID'], defaults = new_values)
if not was_created:
product.product_code = slugify(record['Product Code'])
product.msrp = record['Suggested Retail']
#etc...
product.save()
I don't like the DRY violation, but a model instance doesn't have an update() method like a queryset for me to dump the kwargs into -- unless I'm missing something.
Shawn
I really would love the see this dictionary like access:
obj=MyModel.objects.get(primary_key)
if obj is None:
... does not exist.
But the ticket was closed:
http://code.djangoproject.com/ticket/5741
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de