Implementing Multiple User Classes #1377
erik-at-techsanity
started this conversation in
General
Replies: 1 comment
-
It looks like you are using root to do the search. Since the default parameter https://beanie-odm.dev/tutorial/inheritance/#find-operations You can refer to the source code to find the relevant part of the query. I see that Here's an example of rewriting Document, I just tested it and it works. class User(BeanieBaseUser, Document):
@classmethod
async def get(
cls,
*args,
with_children: bool = True,
**pymongo_kwargs,
):
return await super().get(with_children=with_children, *args, **pymongo_kwargs)
@classmethod
async def find_one(
cls,
*args,
with_children: bool = True,
**pymongo_kwargs,
):
return await super().find_one(with_children=with_children, *args, **pymongo_kwargs)
class Settings:
is_root = True
...
class ApplicationAdministrator(User):
...
class LocationAdministrator(User):
... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
Does anyone have any insight in how to implement seperate user classes that inherit from User? In my case I'd like to create ApplicationAdministrator, LocationAdministrator and Applicant user classes. I get that I could store this as a field in the user class; but in my case I have extra information to be stored for Applicant user types. I'm using Beanie as a backend, and I've included this in the User class:
class Settings(BeanieBaseUser.Settings):
is_root = True
when I include the above, I can create users and I see this in the created document:
_class_id: "User.ApplicationAdministrator"
which is great, but I'm receiving "Auth ErrorError: Bad Request" responses when trying to log in.
I'm open to other ways to do this; I could have an Enum in the User class to state which user type we're dealing with, and then have a separate Profile collection to store their data... but I'd rather store it all in the Applicant subclass if possible.
I'm going to do some debugging to see if I can find out what I've broken in authentication.
If you've got a link to a working example it would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions