Created accounts model
This commit is contained in:
@@ -1,19 +1,37 @@
|
||||
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.sections import TableSection, TemplateSection
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class UnfoldUserAdmin(DjangoUserAdmin, ModelAdmin):
|
||||
list_display = DjangoUserAdmin.list_display + ("last_login", "date_joined")
|
||||
readonly_fields = ("last_login", "date_joined")
|
||||
ordering = ("-date_joined",)
|
||||
from .models import Account
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.firstname} {self.lastname}"
|
||||
|
||||
# Unregister the default User admin and register with Unfold
|
||||
try:
|
||||
admin.site.unregister(User)
|
||||
except admin.sites.NotRegistered:
|
||||
pass
|
||||
# # Register your models here.
|
||||
# admin.site.register(Account)
|
||||
|
||||
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,
|
||||
]
|
||||
24
app/apps/accounts/migrations/0001_initial.py
Normal file
24
app/apps/accounts/migrations/0001_initial.py
Normal 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)),
|
||||
],
|
||||
),
|
||||
]
|
||||
17
app/apps/accounts/migrations/0002_rename_accounts_account.py
Normal file
17
app/apps/accounts/migrations/0002_rename_accounts_account.py
Normal 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',
|
||||
),
|
||||
]
|
||||
0
app/apps/accounts/migrations/__init__.py
Normal file
0
app/apps/accounts/migrations/__init__.py
Normal 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)
|
||||
|
||||
@@ -146,24 +146,32 @@ UNFOLD = {
|
||||
"SITE_DROPDOWN": [
|
||||
{
|
||||
"icon": "diamond",
|
||||
"title": _("Keywarden"),
|
||||
"title": _("Keywarden Development"),
|
||||
"link": "https://keywarden.dev.ntbx.io",
|
||||
"attrs": {
|
||||
"target": "_blank",
|
||||
},
|
||||
},
|
||||
{
|
||||
"icon": "diamond",
|
||||
"title": _("Keywarden [Inactive]"),
|
||||
"link": "https://keywarden.ntbx.io",
|
||||
"attrs": {
|
||||
"target": "_blank",
|
||||
},
|
||||
},
|
||||
|
||||
],
|
||||
# "TABS": [
|
||||
# {
|
||||
# "models": [
|
||||
# "app_label.Accounts",
|
||||
# "keywarden.accounts",
|
||||
# ],
|
||||
# "items": [
|
||||
# {
|
||||
# "title": _("Accounts"),
|
||||
# "link": reverse_lazy("admin:app_label_model_name_changelist"),
|
||||
# "permission": "keywarden.settings.permission_callback",
|
||||
# "link": reverse_lazy("admin:accounts"),
|
||||
# "permission": "keywarden.permission_callback",
|
||||
# },
|
||||
# ],
|
||||
# },
|
||||
|
||||
Reference in New Issue
Block a user