Skip to content

Commit ff5d43f

Browse files
committed
added superuser and last_login fields to BaseUser
1 parent 5d0b740 commit ff5d43f

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from piccolo.apps.migrations.auto import MigrationManager
2+
from piccolo.columns.column_types import Boolean
3+
from piccolo.columns.column_types import Timestamp
4+
from piccolo.columns.indexes import IndexMethod
5+
6+
7+
ID = "2021-04-30T16:14:15"
8+
VERSION = "0.18.2"
9+
10+
11+
async def forwards():
12+
manager = MigrationManager(migration_id=ID, app_name="user")
13+
14+
manager.add_column(
15+
table_class_name="BaseUser",
16+
tablename="piccolo_user",
17+
column_name="superuser",
18+
column_class_name="Boolean",
19+
column_class=Boolean,
20+
params={
21+
"default": False,
22+
"null": False,
23+
"primary": False,
24+
"key": False,
25+
"unique": False,
26+
"index": False,
27+
"index_method": IndexMethod.btree,
28+
},
29+
)
30+
31+
manager.add_column(
32+
table_class_name="BaseUser",
33+
tablename="piccolo_user",
34+
column_name="last_login",
35+
column_class_name="Timestamp",
36+
column_class=Timestamp,
37+
params={
38+
"default": None,
39+
"null": True,
40+
"primary": False,
41+
"key": False,
42+
"unique": False,
43+
"index": False,
44+
"index_method": IndexMethod.btree,
45+
},
46+
)
47+
48+
return manager

piccolo/apps/user/tables.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import secrets
77
import typing as t
88

9-
from piccolo.columns import Varchar, Boolean, Secret
9+
from piccolo.columns import Varchar, Boolean, Secret, Timestamp
1010
from piccolo.columns.readable import Readable
1111
from piccolo.table import Table
1212
from piccolo.utils.sync import run_sync
@@ -23,7 +23,19 @@ class BaseUser(Table, tablename="piccolo_user"):
2323
last_name = Varchar(null=True)
2424
email = Varchar(length=255, unique=True)
2525
active = Boolean(default=False)
26-
admin = Boolean(default=False)
26+
admin = Boolean(
27+
default=False, help_text="An admin can log into the Piccolo admin GUI."
28+
)
29+
superuser = Boolean(
30+
default=False,
31+
help_text=(
32+
"If True, this user can manage other users's passwords in the "
33+
"Piccolo admin GUI."
34+
),
35+
)
36+
last_login = Timestamp(
37+
null=True, default=None, help_text="When this user last logged in."
38+
)
2739

2840
def __init__(self, **kwargs):
2941
"""

piccolo_conf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
This piccolo_conf file is just here so migrations can be made for Piccolo's own
3+
internal apps.
4+
5+
For example:
6+
7+
python -m piccolo.main migration new user --auto
8+
9+
"""
10+
11+
from piccolo.conf.apps import AppRegistry
12+
from piccolo.engine.postgres import PostgresEngine
13+
14+
15+
DB = PostgresEngine(config={})
16+
17+
18+
# A list of paths to piccolo apps
19+
# e.g. ['blog.piccolo_app']
20+
APP_REGISTRY = AppRegistry(apps=["piccolo.apps.user.piccolo_app"])

0 commit comments

Comments
 (0)