Giter Site home page Giter Site logo

Comments (7)

omerra avatar omerra commented on June 4, 2024

I looked over the past Issues, it seems this was solved, and somehow it was broken again. I tried re adding the 2 lines that were removed from the models.py file:
User._meta.pk = User._fields["id"]
User._meta.pk.value_to_string = lambda obj: smart_text(obj.pk)

However it then failed on setting this attribute, I guess the _meta.pk property is not editable there.
To solve it for now I added these same 2 lines to our own User models.py file, so that now it has the _meta.pk attribute. This seems to work. However I think there should be a solution that will make this work straight from mongoengine

from django-mongoengine.

last-partizan avatar last-partizan commented on June 4, 2024

Hello. I've removed that hack becouse i was added value_to_string method to PkWrapper.

Just checked login on example project, and it works.

from django-mongoengine.

omerra avatar omerra commented on June 4, 2024

Hi,first thanks for the help.
It doesn't work on our project, our settings are as shown in the example.

AUTH_USER_MODEL = 'mongo_auth.MongoUser'
MONGOENGINE_USER_DOCUMENT = 'models.users.User'

We use a custom User model that we created using mongoengine. Not the default model from the auth.
The problem is that the user model that authenticate returns is our own User model, and not mongo_auth.MongoUser.
even if we do MongoUser.objects.get(email="user_email") we get our User model. And so it doesn't containt the PkWrapper and doesn't have the _meta.pk attribute.
Like I said, If we add the _meta.pk attribute to our own model it solves it.
It should be possible to work with a custom User Mongoengine model, and still authenticate in my opinion. It also used to work this way before the split.
Do you have any ideas how to solve this?

from django-mongoengine.

last-partizan avatar last-partizan commented on June 4, 2024

Probably your custom User model uses mongoengine.Document instead of django_mongoengine.Document, so wrappers does not applied

from django-mongoengine.

omerra avatar omerra commented on June 4, 2024

Yes you are right, our custom user model inherits straight from mongoengine.Document.
So the solution should be to inherit from django_mongoengine.Document ?
I see that that inherits from mongoengine.Document it self. So it should be transparent and work, if we inherit from django_mongoengine.Document ?

from django-mongoengine.

last-partizan avatar last-partizan commented on June 4, 2024

Yes, django_mongoengine.Document just add that missing properties required by django stuff

from django-mongoengine.

omerra avatar omerra commented on June 4, 2024

Great, thanks a lot for the help, and for maintaining this library, will try with this change and test it out.
Maybe add to the docs somewhere, that if you use a custom model, you should inherit from django_mongoengine.Document (since before the split, there was no difference between the 2).

This also works with our own custom authentication backends by the way. So it should basically work with any authentication backend.

from django-mongoengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.