mongoengine

MongoEngine User authentication (django)

不打扰是莪最后的温柔 提交于 2019-11-28 18:03:03
I am trying to use MongoEngine in a django project I am writing. I am having difficulty getting (or understanding how) the authentication backend works. The user object as far as I can tell is not stored in the request. I have it working but I am not sure if I am doing it in the right/safe way. If someone could look at my code I would be much appreciated. def login(request): user = authenticate(request.POST['username'],request.POST['password']) if user is not None: request.session['user'] = user if user.is_authenticated: return HttpResponse(user) else: return HttpResponse('login failed') def

mongoengine - Query on ListField of EmbeddedDocumentField

耗尽温柔 提交于 2019-11-28 14:32:12
I use mongoengine with Django and python. This is my code: class Chambre(EmbeddedDocument): max_personne = IntField(default=0) prix = IntField(default=0) class Hotel(Document): code = IntField(default=0) nom = StringField(max_length=200) chambre = ListField(EmbeddedDocumentField(Chambre)) resume = StringField(max_length=200) 1 - I want a query to filter all Hotel that have at least a Chambre with prix >= a (a floeat number) 2 - also have that Chambre Any idea? You can use the embedded notatio n as well as the Query Operator for "greater than or equal " Hotel.objects(chambre__prix__gte=a) Or if

MongoDB using an OR clause in mongoengine

若如初见. 提交于 2019-11-28 07:00:37
问题 I'm using python's mongoengine to query MongoDB, and have loved it for the most part, but I'm having an issue with an advanced query. Here's my model class ContentItem(Document): account = ReferenceField(Account) creator = ReferenceField(User) public = BooleanField(default=False) last_used = DateTimeField(default=datetime.now) I would like to make a query for all ContentItem 's that are of a particular account, and are either created by the logged in user or are public. Here's the query I

Django - Auth with mongoengine DB

筅森魡賤 提交于 2019-11-28 06:36:06
I want to handle authentications in my Django project with my mongoengine db. I tried a few examples about this stuff answered in old questions but it didn't run. I'm using Django 1.6 and mongoengine. Everything is installed, running and I can create and save documents to my Mongoengine DB. I'm following http://mongoengine-odm.readthedocs.org/en/latest/django.html And i get the following error: When i run: >>> from django.contrib.auth.models import User >>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') I get this: Traceback (most recent call last): File "

Mongoengine: TypeError: __init__() got an unexpected keyword argument

假如想象 提交于 2019-11-28 05:09:00
问题 I am using flask-mongoengine extension and I have a User class like this: class User(db.Document, UserMixin): email = db.StringField(max_length=120, required=True, unique=True) password_hash = db.StringField(max_length=80, required=True) active = db.BooleanField() fb_id = db.StringField(max_length=120, required=False) def __init__(self, email, password, fb_id=None, active=True): hashp = md5.md5(password).hexdigest() self.email=email self.password_hash=hashp self.fb_id=fb_id self.active=active

How to get ReferenceField data in mongoengine?

☆樱花仙子☆ 提交于 2019-11-28 04:11:06
问题 I'm have a problem that query set retrieving oid in json, and I would like to retrieve actual username of that User collection I have below: class User(db.Document): username = db.StringField(required=True) password_hash = db.StringField() is_admin = db.IntField(default=0) class Message(db.EmbeddedDocument): to_users = db.ListField(db.ReferenceField(User)) created_at = db.DateTimeField(default=datetime.now) is_read = db.BooleanField(default=False) body = db.StringField(required=True) class

How to query for distinct results in mongodb with python?

a 夏天 提交于 2019-11-28 04:03:54
问题 I have a mongo collection with multiple documents, suppose the following (assume Tom had two teachers for History in 2012 for whatever reason) { "name" : "Tom" "year" : 2012 "class" : "History" "Teacher" : "Forester" } { "name" : "Tom" "year" : 2011 "class" : "Math" "Teacher" : "Sumpra" } { "name" : "Tom", "year" : 2012, "class" : "History", "Teacher" : "Reiser" } I want to be able to query for all the distinct classes "Tom" has ever had, even though Tom has had multiple "History" classes

Mongoengine: ConnectionError: You have not defined a default connection

家住魔仙堡 提交于 2019-11-28 04:03:15
问题 In my new Django project I set up a MongoDb database and use mongoengine module but I can't properly access to dabase nore in shell no in views. "ConnectionError: You have not defined a default connection" My settings.py includes the following: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'DaTaBaSe', 'USER': 'root', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '3306', }, 'tracking': { 'ENGINE': 'django.db.backends.dummy', 'NAME': 'analytics', } } import mongoengine

MongoEngine: EmbeddedDocument v/s. ReferenceField

余生长醉 提交于 2019-11-28 01:37:33
EmbeddedDocument will allow to store a document inside another document, while RefereneField just stores it's reference. But, they're achieving a similar goal. Do they have specific use cases? PS: There's already a question on SO, but no good answers. The answer to this really depends on what intend to do with the data you are storing in mongodb. It is important to remember that a ReferenceField will point to a document in another collection in mongodb, whereas an EmbeddedDocument is stored in the same document in the same collection. Consider this schema: Person -> name -> address Address ->

Flask throwing 'working outside of request context' when starting sub thread

荒凉一梦 提交于 2019-11-27 17:35:50
I am trying to start a new thread in Python inside of a Flask application. I am doing background work that gets triggered by the request, but I don't need to wait for the work to be done to respond to the request. Is it possible to set the flask request in this sub-threat to the request that came in? Reason being, our ACL on our queries to our DB (mongoengine in front of mongoDB) relies on the request's user (it grabs it from flask's request object) to see if they have access to the objects, and its blowing up because the request is not available in the sub-thread. Any thoughts would be much