Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MongoEngine models for cross-benchmarks
from mongoengine import *
class ProductList(Document):
name = StringField(required=True, unique=True)
def import_offers(self, offers):
for o in Offer.objects.filter(productlist=self.name):
o.old=True
o.save()
for offer in offers:
try:
o = Offer.objects.get(
productlist=self.name, articlenumber=offer['articlenumber'])
except Offer.DoesNotExist:
o = Offer(
productlist=self.name, articlenumber=offer['articlenumber'],
)
o.productlist = self.name
o.title = offer['title']
# Update a bunch of fields
# ...
o.old = False
o.save()
query = Offer.objects.filter(productlist=self.name, old=True)
if query:
query.delete()
class Offer(Document):
articlenumber = StringField(required=True)
title = StringField()
productlist = StringField()
# Define a bunch of fields
# ...
old = BooleanField(default=False)
meta = {
'indexes': [('articlenumber', 'productlist')]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.