pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
BSD 3-Clause "New" or "Revised" License
5.69k stars 1.56k forks source link

[not issue] Implement flask-admin in Go #2428

Open pedia opened 1 month ago

pedia commented 1 month ago

Flask-Admin is my favorite framework and used it in many projects.

Since I moved to Go, I started port flask-admin to Go gadmin. Now I publish a preview version. Maybe someone is interesting this.

Below simple/main.go

package main

import (
    "gadmin"
    "time"

    "github.com/google/uuid"
)

type User struct {
    Id                       string `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()"`
    Type                     string
    EnumChoiceField          string `a:"enum:1=first,2=second;"`
    SqlaUtilsChoiceField     string
    SqlaUtilsEnumChoiceField int
    FirstName                string
    LastName                 string
    Email                    string
    Website                  string
    IpAddress                string `gorm:"comment:last logined ip address"`
    Currency                 string
    Timezone                 string
    DiallingCode             int
    LocalPhoneNumber         string
    FeaturedPostId           int
}

type Post struct {
    Id              int    `gorm:"primaryKey"`
    Title           string `gorm:"size:120"`
    Text            string
    Date            time.Time
    BackgroundColor string
    CreatedAt       time.Time `gorm:"default:CURRENT_TIMESTAMP"`
    UserId          uuid.UUID
    User            *User `gorm:"foreignKey:UserId"`
}

type Tag struct {
    Id   int    `gorm:"primaryKey"`
    Name string `gorm:"uniqueIndex"`
}

func main() {
    admin := gadmin.NewAdmin("Example: Simple Views")
    admin.AddView(gadmin.NewView("Test", "view1"))
    admin.AddView(gadmin.NewView("Test", "view2"))

    mv := gadmin.NewModalView(User{}).
        SetColumnList("type", "first_name", "last_name", "email", "ip_address", "currency", "timezone", "phone_number").
        SetColumnEditableList("first_name", "type", "currency", "timezone").
        SetColumnDescriptions(map[string]string{"first_name": "ๅ"}).
        SetCanSetPageSize(true).
        SetPageSize(5).
        SetTablePrefixHtml(`<h4>hello</h4>`)
    admin.AddView(mv)
    admin.AddView(gadmin.NewModalView(Post{}))
    admin.AddView(gadmin.NewModalView(Tag{}))
    admin.Run()
}

All template files are copied from flask-admin(bootstrap4 only).

hasansezertasan commented 1 month ago

Looks interesting, well done๐Ÿ‘. One thing caught yo me eye is that there is not any license file. I recommend adding one since it's not very convenient to use unlicensed software.

Good luck ๐Ÿ˜‡.

pedia commented 1 month ago

Looks interesting, well done๐Ÿ‘. One thing caught yo me eye is that there is not any license file. I recommend adding one since it's not very convenient to use unlicensed software.

Good luck ๐Ÿ˜‡.

MIT added Thanks