3
votes

Does anyone have specific examples of using the authentication from Mongoengine?

A couple questions I have are:

extending the User class

from mongoengine.django.auth import User
from mongoengine import *

class User(User):
    location =  GeoPointField()

When I create a user with no documents are saved

User.create_user('bob','bobpass','[email protected]')
User.objects
>>>[]

explicitly call the .save() method has the same affect

Can the User class not be inherited?

Also

Is there a login() method like in the standard authentication backend?

I am starting to feel like I am trying to put a square peg in a round hole with MongoDB and Django...

2

2 Answers

2
votes

I haven't used MongoEngine, but I've been looking at it documentation.

First, don't use the User name for your extension, there could be name clashes. Call it for example Profile:

from mongoengine.django.auth import User
from mongoengine import *

class Profile(User):
    location =  GeoPointField()

If that is not working, try:

class Profile(Document):
    user = ReferenceField(User)
    location =  GeoPointField()

For your login question, look at this.

0
votes

create instance.

user = User.create_user('bob','bobpass','[email protected]')
user.save()

or

user = User(username='bob', password='bobpass', email='[email protected]')
user.save()

or

user = User()
user.username = 'bob'
user.password = 'bobpass'
user.email = '[email protected]'
user.save()