Mind Juice

J U S T · A · S A F E T Y · N E T
  • DL
    • Introduction
    • Neural Network
  • Back-End
    • Flask
      • Flask Basics
      • Login & Logout
      • Broadcasting
      • Relationships
      • All App Files
      • The Memoirs Project
    • Django
      • Django Basics
      • Coding Entrepreneurs
    • Dev. Tech
      • Infrastructure
      • HTTP & REST
      • GitHub
    • Database
      • Relational Databases
    • Linux
      • Ubuntu
      • Command Line
  • Python
    • Setup Python
    • Python Basics
    • Python Collection
      • Lists
      • Dictionaries
      • Tuples
      • Sets
      • Game Practice
    • Object-Oriented Python
    • DB in Python
    • Better Python
    • Comprehension
    • Dates & Times
    • Regular Expressions
    • Type Hinting
    • Files I/O
    • Python Testing
  • JavaScript
    • JavaScript Basics
    • ES2015
    • jQuery
    • DOM Scripting
    • Callback Functions
    • Array Iteration
    • OOP
    • Regular Expressions
    • Pseudocode
    • Closures
    • Local Storage
    • AJAX & JSON
    • Async. Programming
    • Mobile Web Apps
    • React
  • Front-End
    • HTML
    • CSS & Sass
      • CSS
      • Flexbox
      • CSS Variables
      • CSS Grid
      • CSS Best Practices
      • CSS to Sass
      • Sass
    • Bootstrap 5
    • Chrome DevTools
    • Front End Optimizing
      • Gulp
      • FE Optimization Workflow
      • CHECKLIST
    • Web Accessibility
    • SEO & Digital Marketing
  • Design
    • Foundations
    • Branding
    • Typography
    • UX
      • Design Thinking
      • Wireframing
      • Dev. Collaboration
      • Feedback
    • Freelance
    • Multimedia

User Model

  • Mind Juice
    • Register, Login & Logout
  • User Model

User Model

Aug 01 2016- POSTED BY projecth Comments Off on User Model

Building The Model

First we’ll build the model that will handle the credential data of the registering users.

[models.py]

import datetime 

from flask.ext.login import UserMixin
from peewee import *

DATABASE = SqliteDatabase('social.db')

class User(UserMixin, Model):
	username = CharField(unique=True)
	email = CharField(unique=True)
	password = CharField(max_length=100)
	joined_at = DateTimeField(default=datetime.datetime.now)
	is_admin = BooleanField(default=False)

	class Meta:
		database = DATABASE
		order_by = ('-joined_at',)


order_by = (‘-joined_at’,)

Orders registered users when listing them by the order of their joining date, new first descending to old.


Flask-Login

To use this great package, you first need to install it.

pip install flask-login

flask-login
A package that handles user sessions. For now we’re only going to use one of its functionalities: UserMixin.

UserMixin
Provides us with a few properties about the user’s login status that we will make use of later, and they are:
is_authenticated, is_active, is_anonymous, get_id()

from flask.ext.login import UserMixin
Imports UserMixin from the flask-login package, which in the Flask echo-system as all packages is installed to this ext module, which stands for External Area.

class User( UserMixin, Model ):
UserMixins must be inherited first, then the Model.

  • Previous
  • Next
All rights reserved Mind Juice 2020.
Proudly powered by WordPress | Theme: Flatter by SpiceThemes