title: Django - Auth with mongoengine DB
body: <p>I want to handle authentications in my Django project with my mongoengine db.</p>
  
  <p>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.</p>
  
  <p>I'm following <a href="http://mongoengine-odm.readthedocs.org/en/latest/django.html" rel="noreferrer">http://mongoengine-odm.readthedocs.org/en/latest/django.html</a></p>
  
  <p>And i get the following error:</p>
  
  <p>When i run:</p>
  
  <pre><code>&gt;&gt;&gt; from django.contrib.auth.models import User
  &gt;&gt;&gt; user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
  </code></pre>
  
  <p>I get this: </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/REBORN/reb_env/local/lib/python2.7/site-packages/django/db/models/manager.py", line 273, in __get__
      self.model._meta.object_name, self.model._meta.swapped
  AttributeError: Manager isn't available; User has been swapped for 'mongo_auth.MongoUser'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I really don't understand 2 things:</p>
  
  <p>-Do I must create and define the database where the users will be stored or they will be created automatically?</p>
  
  <p>-What is Manager? I haven't defined any manager stuff </p>
  
  <p>At the beggining i thought that the register was saved in a db. callled 'mongo_auth.MongoUser' but it didn't save it in nowhere.</p>
  
  <p>Here is the models:</p>
  
  <pre><code># Create your models here.
  from mongoengine import *
  
  class Profile(Document):
      email = StringField(required=True)
      first_name = StringField(max_length=50)
      last_name = StringField(max_length=50)
  
  class auth_user(Document):
      username = StringField(max_length=50)
      email = StringField(max_length=50)
      password = StringField(max_length=50)
  </code></pre>
  
  <p>The settings.py is properly configured as the manual says.</p>
  
  <p>EDIT @cestDiego:</p>
  
  <p>My settings are exactly the same, I've noticed about the Db backend because it creates me a database which am not interested because I use mongo...Anyway I'm ussing from mongoengine.django.auth import User now but when I try to create an User it returns me : </p>
  
  <pre><code>&gt;&gt;&gt; user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
  AttributeError: 'QuerySet' object has no attribute 'create_user'
  </code></pre>
  
  <p>Maybe we are customizing the auth and that's why not work, no idea. Do you have this problem too ?</p>
  
  <p>SECOND EDIT:</p>
  
  <p>I was reading and we have to use Djangos auth, after configure the right settings, as both we have done.</p>
  
  <p>Then must import the from django.contrib.auth import authenticate and use authenticate as it is provided in Django docs, hope to help ;D.</p>
  
  <pre><code>from django.shortcuts import render
  # Create your views here.
  from django.http import HttpResponse
  from game.models import *
  from mongoengine import *
  from models import User
  from django.contrib.auth import authenticate
  
  def login(request):
          user = authenticate(username='john', password='secret')
          if user is not None:
              # the password verified for the user
              if user.is_active:
                  print("User is valid, active and authenticated")
              else:
                  print("The password is valid, but the account has been disabled!")
          else:
              # the authentication system was unable to verify the username and password
              print("The username and password were incorrect.")
  </code></pre>