Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to .create_table() and insert user for peewee-admin to be useful? #158

Open
kramer65 opened this issue Oct 22, 2014 · 7 comments
Open

Comments

@kramer65
Copy link

In response to the issue I opened yesterday here I just now see that peewee-admin is not part of peewee, but rather of flask-peewee.

So in order to not get in the way with peewee-admin, I renamed my own User class to something different, but I now get an error saying no such table: user. I suppose I need to do a .create_table() on the User class which is defined here, but I wouldn't know when and where to run that .create_table(). Furthermore, I suppose I would also need to insert a user in the user table, but for this I also wouldn't know when and where?

Are there any docs that describe this, or would you otherwise explain me here how I could do that? All tips are welcome!

@kramer65
Copy link
Author

Okay, I got it working. I subclassed the Auth and Admin classes and just overrid some methods as follows (VG is the name of my website):

class VGAuth(Auth):
    def authenticate(self, username, password):
        if g.user is not None and g.user.is_authenticated():
            return g.user._get_current_object()
        else:
            return False

    def get_logged_in_user(self):
        if g.user is not None and g.user.is_authenticated():
            return g.user._get_current_object()
        else:
            return False

    def load_user(self):
        g.user = current_user


class VGAdmin(Admin):
    def check_user_permission(self, user):
        return True


adminAuth = VGAuth(app, relDb, user_model=User)
admin = VGAdmin(app, adminAuth)

The result is that I now need to login using LinkedIn, then go to the admin login page, enter any credentials (anything will work, since it only checks if the user already logged in using LinkedIn) and hit enter. Although not ideal, it does work now.. :)

If you think there's anything wrong with this way of doing it, I would be very happy to know! If not; thanks for creating peewee, it's the best Python ORM out there!

@coleifer
Copy link
Owner

Thanks for posting your findings, I think your approach looks sane but not knowing your application as well as you do, I'm not sure I can comment on how correct things are. Good luck and glad you're enjoying working with peewee!

@kramer65
Copy link
Author

One last question: is there a way to change the admin base url from /admin/ to something different like /my-awesome-peewee-admin. I would like to use the /admin route for the user admin part..

@coleifer
Copy link
Owner

I believe when instantiating your Admin you pass in a different "prefix", e.g.

admin = Admin(app, auth, prefix='/my-awesome-peewee-admin)

@kramer65
Copy link
Author

That's what I thought as well, but it doesn't seem to work. Also, the default seems to be '/accounts', not '/admin': https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/auth.py#L42

@coleifer
Copy link
Owner

Hmm...I'm not sure why that isn't working.

@dommert
Copy link

dommert commented Nov 11, 2014

the prefix tag works just fine. i moved my admin with that syntax. I also used subdomain='name' and then it would become name.domain.com. so im not sure what you are doing wrong. coleifer just did a flask blueprint for /admin so if you need to did deeper read about flask blueprints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants