Django : proper way to use model, duplicates!
Posted
by llazzaro
on Stack Overflow
See other posts from Stack Overflow
or by llazzaro
Published on 2010-03-12T20:53:43Z
Indexed on
2010/03/12
20:57 UTC
Read the original article
Hit count: 375
Hello,
I have a question about the proper, best way to manage the model. I am relative newbie to django, so I think I need to read more docs, tutorials,etc (suggestions for this would be cool!).
Anyway, this is my question :
I have a python web crawler, that is "connected" with django model.
Crawling is done once a day, so its really common to find "duplicates". To avoid duplicates I do this :
cars = Car.Objects.filter(name=crawledItem['name'])
if len(cars) > 0:
#object already exists, update it
car = cars[0]
else:
car = Car()
#some non-relevant code here
car.save()
I want to know, if this is the proper/correct way to do it or its any "automatic" way to do it.
Its possible to put the logic inside the Car() constructor also, should I do that?
Thanks a lot!
© Stack Overflow or respective owner