Skip to content

Instantly share code, notes, and snippets.

@tobami
Created February 17, 2011 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobami/831774 to your computer and use it in GitHub Desktop.
Save tobami/831774 to your computer and use it in GitHub Desktop.
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