uAdmin Tutorial Part 4 - Register Inlines and Drop Down List

Inlines is where we keep all registered models’ inlines. It allows you to merge a parent model to a submodel where the foreign key(s) are specified.

Why do we use Register Inlines? We use them to show that the field of a model is related to another model as long as there is a foreign key specified.

Structure:

uadmin.RegisterInlines(/folder_name/./struct_name of a parent model/{}, map[string]string{
    "/sub_model name/": "/parent_model name/ID",
})

Now let’s apply it in the main.go. Copy the codes below and paste it after the uadmin.Register function.

uadmin.RegisterInlines(models.Category{}, map[string]string{
    "Todo": "CategoryID",
})
uadmin.RegisterInlines(models.Friend{}, map[string]string{
    "Todo": "FriendID",
})

Let’s run the application and see what happens.

../_images/registerinlinetodo.png

Tada! The parent model Todo is now included in the Category submodel as shown above. You can go to Friends and Items models and it will display the same result.