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

rich_editor to field #231

Open
ghost opened this issue Aug 7, 2020 · 1 comment
Open

rich_editor to field #231

ghost opened this issue Aug 7, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 7, 2020

Hi,

Hope you are all well !

I would like to create a small cms and creating blocks of html content like medium.com. For doing that I need to use the rich editor for the sub-blocks in the admin form.
Screenshot 2020-08-07 at 13 47 59

How can I apply the rich_editor meta to additional blocks like in the screenshot ?

Please find below my test code.

package main

import (
	"fmt"
	"net/http"

	"github.com/jinzhu/gorm"
	_ "github.com/mattn/go-sqlite3"
	"github.com/qor/admin"
	"github.com/qor/media/media_library"
	"github.com/qor/publish2"
	qor_seo "github.com/qor/seo"
	"github.com/qor/slug"
)

type User struct {
	gorm.Model
	Username string
	Email    string
	Disabled bool
}

type Page struct {
	gorm.Model
	User          User
	UserID        uint
	Title         string `gorm:"type:mediumtext; CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" sql:"type:mediumtext"`
	Content       string `gorm:"type:longtext; CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" sql:"type:longtext"`
	TitleWithSlug slug.Slug
	Blocks        []Block
	Media         media_library.MediaLibrary
	publish2.Version
	publish2.Schedule
	publish2.Visible
	Seo qor_seo.Setting
}

type Block struct {
	gorm.Model
	PageID      uint
	Title       string `gorm:"type:mediumtext; CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" sql:"type:mediumtext"`
	Description string `gorm:"type:longtext; CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" sql:"type:longtext"`
	Media       media_library.MediaLibrary
}

func main() {
	DB, _ := gorm.Open("sqlite3", "cms.db")
	DB.AutoMigrate(&User{})
	DB.AutoMigrate(&Page{})
	DB.AutoMigrate(&Block{})

	// Initialize
	Admin := admin.New(&admin.AdminConfig{DB: DB})

	// Allow to use Admin to manage User, Product
	Admin.AddResource(&User{})
	page := Admin.AddResource(&Page{})
	page.Meta(&admin.Meta{
		Name: "Content",
		Type: "rich_editor",
	})

	// initalize an HTTP request multiplexer
	mux := http.NewServeMux()

	// Mount admin interface to mux
	Admin.MountTo("/admin", mux)

	fmt.Println("Listening on: 9000")
	http.ListenAndServe(":9000", mux)
}

Thanks in advance for your help and insights about that.

Cheers,
X

@han2015
Copy link
Contributor

han2015 commented Jun 29, 2021

Hi @x0rzkov
you should also do rich_editor meta config on block Description.

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

1 participant