1.更新数据库结构,添加菜单表、角色表、角色菜单表、角色用户表

This commit is contained in:
jayhgq 2024-09-17 17:14:15 +08:00
parent 4e8c817880
commit f1ec97436d
6 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,52 @@
# Generated by Django 5.1 on 2024-09-17 09:09
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Menu',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')),
('menu_name', models.CharField(max_length=50, verbose_name='菜单名称')),
('parent_id', models.IntegerField(max_length=50, verbose_name='父菜单')),
('path', models.CharField(max_length=128, verbose_name='路由地址')),
('order', models.IntegerField(default=0, max_length=5, verbose_name='排序')),
('create_time', models.DateTimeField(verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='最后更新时间')),
],
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')),
('role_name', models.CharField(max_length=50, verbose_name='角色名称')),
('role_name_en', models.CharField(max_length=50, verbose_name='角色英文名称')),
('create_time', models.DateTimeField(verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='最后更新时间')),
],
),
migrations.CreateModel(
name='RoleMenu',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')),
('menu_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.menu', verbose_name='菜单ID')),
('role_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.role', verbose_name='角色ID')),
],
),
migrations.CreateModel(
name='RoleUser',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')),
('role_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.role', verbose_name='角色ID')),
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.user', verbose_name='用户ID')),
],
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 5.1 on 2024-09-17 09:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth', '0002_menu_role_rolemenu_roleuser'),
]
operations = [
migrations.AlterField(
model_name='menu',
name='order',
field=models.IntegerField(default=0, verbose_name='排序'),
),
migrations.AlterField(
model_name='menu',
name='parent_id',
field=models.IntegerField(verbose_name='父菜单'),
),
]

View File

@ -35,3 +35,33 @@ class User(models.Model):
return self.avatar.url
else:
return '/media/avatar/default.jpg'
class Menu(models.Model):
id = models.AutoField(verbose_name="id", primary_key=True, unique=True)
menu_name = models.CharField(verbose_name="菜单名称", max_length=50, null=False, blank=False)
parent_id = models.IntegerField(verbose_name="父菜单")
path = models.CharField(verbose_name="路由地址", max_length=128)
order = models.IntegerField(verbose_name="排序", default=0)
create_time = models.DateTimeField(verbose_name="创建时间")
update_time = models.DateTimeField(verbose_name="最后更新时间", auto_now=True)
class Role(models.Model):
id = models.AutoField(verbose_name="id", primary_key=True, unique=True)
role_name = models.CharField(verbose_name="角色名称", max_length=50, null=False, blank=False)
role_name_en = models.CharField(verbose_name="角色英文名称", max_length=50)
create_time = models.DateTimeField(verbose_name="创建时间")
update_time = models.DateTimeField(verbose_name="最后更新时间", auto_now=True)
class RoleMenu(models.Model):
id = models.AutoField(verbose_name="id", primary_key=True, unique=True)
menu_id = models.ForeignKey(verbose_name="菜单ID", to="Menu", to_field="id", on_delete=models.CASCADE)
role_id = models.ForeignKey(verbose_name="角色ID", to="Role", to_field="id", on_delete=models.CASCADE)
class RoleUser(models.Model):
id = models.AutoField(verbose_name="id", primary_key=True, unique=True)
role_id = models.ForeignKey(verbose_name="角色ID", to="Role", to_field="id", on_delete=models.CASCADE)
user_id = models.ForeignKey(verbose_name="用户ID", to="User", to_field="id", on_delete=models.CASCADE)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB