Register Functions

Back To uAdmin Functions List

In this section, we will cover the following functions in-depth listed below:

uadmin.Register

Back To Top

func Register(m ...interface{})

Register is used to register models to uAdmin.

Parameter:

m …interface{}: Is the model that you want to add in the dashboard

Used in the tutorial:

Create an internal Todo model inside the main.go. Afterwards, call the Todo{} inside the uadmin.Register so that the application will identify the Todo model to be added in the dashboard.

// Todo model ...
type Todo struct {
    uadmin.Model
    Name        string
    Description string `uadmin:"html"`
    TargetDate  time.Time
    Progress    int `uadmin:"progress_bar"`
}

func main() {
    uadmin.Register(Todo{}) // <-- place it here
}

Output

../_images/uadmindashboard.png

If you click the Todos model, it will display this result as shown below.

../_images/todomodel.png

Quiz:

uadmin.RegisterInlines

Back To Top

func RegisterInlines(model interface{}, fk map[string]string)

RegisterInlines is a function to register a model as an inline for another model.

Parameters:

model (struct instance): Is the model that you want to add inlines to.

fk (map[interface{}]string): This is a map of the inlines to be added to the model. The map’s key is the name of the model of the inline and the value of the map is the foreign key field’s name.

Used in the tutorial:

Example:

type Person struct {
    uadmin.Model
    Name string
}

type Card struct {
    uadmin.Model
    PersonID uint
    Person   Person
}

func main() {
    // ...
    uadmin.RegisterInlines(Person{}, map[string]string{
        "Card": "PersonID",
    })
    // ...
}

Quiz: