Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Yunti
Thanks - you've definitely given me some stuff to think about. I'm doing XHR requests - returning JSON for the scraping (but probably later will have normal pages so I will definitely look at your Etag suggestion - I'm not familiar with that so will look into it). Given it's XHR and JSON I pr

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Dan Tagg
If you are web scraping you really need your code to be as efficient as possible and to do as little as possible. Firstly, make sure you are using everything the servers of the websites you are scraping are giving you to decide whether to bother downloading the page. For example, check the etag and

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Yunti
Hi Dan, Thanks for the suggestion, it's a web scraper (run as a django management command) which then saves the data to the database via the Django ORM. Given it's a scraper rather than a form (or view) is the above suggested function an ok way to proceed or would you suggest something else is

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Dan Tagg
Hi Yunti, You could go up a level in the structure of your application and apply the logic there, where there is more support. Are you using Django forms? The ModelForm class pretty much does what you want, it examines form data, validating it against its type and any validation rules you have s

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Yunti
Jani, Thanks for your reply - you explained it much more concisely than I did. :) Good to have it confirmed that update_or_create() doesn't quite do what I needed - I was confused as to whether it would or not. Thanks for taking the time to do that function, that looks ideal. I'll test it out.

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Jani Tiainen
Your problem lies on the way Django actually carries out create or update. As name suggest, create or update does either one. But that's what you don't want - you want conditional update. Only update if certain fields have been changed. Well this can be done few ways. So you want to do "up

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Yunti
Carsten , Thanks for your reply, A note about the last statement: If a Supplier object has the same unique_id, and all other fields (in `defaults`) are the same as well, logically there is no difference between updating and not updating – the result is the same. The entry in the database is

Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Yunti
Carsten , Thanks for your reply, A note about the last statement: If a Supplier object has the same unique_id, and all other fields (in `defaults`) are the same as well, logically there is no difference between updating and not updating – the result is the same. The entry in the database is

Re: update_or_create() always creates (or recreates)

2015-11-05 Thread Carsten Fuchs
Hi Yunti, Am 05.11.2015 um 18:19 schrieb Yunti: I have tried to use the update_or_create() method assuming that it would either, create a new entry in the db if it found none or update an existing one if it found one and had differences to the defaults passed in - or wouldn't update if there

update_or_create() always creates (or recreates)

2015-11-05 Thread Yunti
I have tried to use the update_or_create() method assuming that it would either, create a new entry in the db if it found none or update an existing one if it found one and had differences to the defaults passed in - or wouldn't update if there was no difference. However it just seemed to rec