Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pedia opened this issue May 15, 2024 · 2 comments
Open

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

pedia opened this issue May 15, 2024 · 2 comments

Comments

@pedia
Copy link

pedia commented May 15, 2024

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
Copy link

hasansezertasan commented May 15, 2024

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
Copy link
Author

pedia commented May 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants