Created accounts model

This commit is contained in:
2025-11-11 09:42:50 +00:00
parent c488f18cc6
commit 7021035f94
6 changed files with 90 additions and 16 deletions

View File

@@ -1,19 +1,37 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from unfold.admin import ModelAdmin from unfold.admin import ModelAdmin
from unfold.sections import TableSection, TemplateSection
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
class UnfoldUserAdmin(DjangoUserAdmin, ModelAdmin): from .models import Account
list_display = DjangoUserAdmin.list_display + ("last_login", "date_joined")
readonly_fields = ("last_login", "date_joined")
ordering = ("-date_joined",)
def __str__(self):
return f"{self.firstname} {self.lastname}"
# Unregister the default User admin and register with Unfold # # Register your models here.
try: # admin.site.register(Account)
admin.site.unregister(User)
except admin.sites.NotRegistered:
pass
admin.site.register(User, UnfoldUserAdmin) # Table for related records
class CustomTableSection(TableSection):
verbose_name = _("Keywarden Users") # Displays custom table title
height = 300 # Force the table height. Ideal for large amount of records
# related_name = "related_name_set" # Related model field name
fields = ["id", "firstname", "lastname", "joined_date"] # Fields from related model
# # Custom field
# def custom_field(self, instance):
# return instance.pk
# # Simple template with custom content
# class CardSection(TemplateSection):
# template_name = "keywarden/some_template.html"
@admin.register(Account)
class SomeAdmin(ModelAdmin):
list_sections = [
#CardSection,
CustomTableSection,
]

View File

@@ -0,0 +1,24 @@
# Generated by Django 5.1 on 2025-11-11 09:19
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Accounts',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('firstname', models.CharField(max_length=255)),
('lastname', models.CharField(max_length=255)),
('email', models.CharField(max_length=255)),
('joined_date', models.DateField(null=True)),
],
),
]

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.1 on 2025-11-11 09:24
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('accounts', '0001_initial'),
]
operations = [
migrations.RenameModel(
old_name='Accounts',
new_name='Account',
),
]

View File

View File

@@ -0,0 +1,7 @@
from django.db import models
class Account(models.Model):
firstname = models.CharField(max_length=255)
lastname = models.CharField(max_length=255)
email = models.CharField(max_length=255)
joined_date = models.DateField(null=True)

View File

@@ -146,24 +146,32 @@ UNFOLD = {
"SITE_DROPDOWN": [ "SITE_DROPDOWN": [
{ {
"icon": "diamond", "icon": "diamond",
"title": _("Keywarden"), "title": _("Keywarden Development"),
"link": "https://keywarden.dev.ntbx.io", "link": "https://keywarden.dev.ntbx.io",
"attrs": { "attrs": {
"target": "_blank", "target": "_blank",
}, },
}, },
{
"icon": "diamond",
"title": _("Keywarden [Inactive]"),
"link": "https://keywarden.ntbx.io",
"attrs": {
"target": "_blank",
},
},
], ],
# "TABS": [ # "TABS": [
# { # {
# "models": [ # "models": [
# "app_label.Accounts", # "keywarden.accounts",
# ], # ],
# "items": [ # "items": [
# { # {
# "title": _("Accounts"), # "title": _("Accounts"),
# "link": reverse_lazy("admin:app_label_model_name_changelist"), # "link": reverse_lazy("admin:accounts"),
# "permission": "keywarden.settings.permission_callback", # "permission": "keywarden.permission_callback",
# }, # },
# ], # ],
# }, # },