Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango-adaptors: How to use correctly the Update meta option
    text
    copied!<p>Thanks for being here reading my question.</p> <p>I am doing a webshop for a photography company and I need to read a csv file to update the products on the database. I am using <a href="http://django-adaptors.readthedocs.org/en/latest/" rel="nofollow">django-adaptors</a> to iterate the file and save the information, now is working good by the first time, but if run the command again the app creates new objects instead of overwrite the existing.</p> <p>The problem is that I don't know what is the correct way to use the Update meta option. (You can see it in <a href="http://django-adaptors.readthedocs.org/en/latest/#meta-options" rel="nofollow">the documentation</a>)</p> <p>This is the code that I have right now:</p> <pre><code>from models import Type, Vendor, Product from adaptor.model import CsvModel from adaptor import fields as adaptor_fields # Prepare functions here, but are not relevant information class csv(CsvModel): mfr_code = adaptor_fields.CharField() main_photo_url = adaptor_fields.CharField() name = adaptor_fields.CharField() product_url = adaptor_fields.CharField() vendor = adaptor_fields.CharField(prepare=get_or_create_vendor) type = adaptor_fields.CharField(prepare=get_or_create_type) subtype = adaptor_fields.IgnoredField() description = adaptor_fields.CharField() specs = adaptor_fields.CharField() tags = adaptor_fields.CharField() stock = adaptor_fields.IntegerField(prepare=get_stock_value) price = adaptor_fields.IntegerField(prepare=format_usd) class Meta: delimiter = ',' dbModel = Product update = { 'keys': ['D1 Basic Kit 250/500', 'D1 Studio Kit 250/250'] } </code></pre> <p>As you can see above I have the dictionary with the 'keys' value, but I don't know how to define the list of 'natural keys' and I am getting a KeyError exception when trying to run the command.</p> <p>Can someone explain me what is the method to do it the right way?</p> <p>Thanks for answering.</p> <p>Cristian</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload