Search code examples
model-view-controllergobeego

Beego - Creating Model Form and ORM


I have created a model using the following code:

type UserProfile struct {
    Id                  int             `orm:"auto"`
    Name                string          `orm:"size(100)"`
    Email               string          `orm:"size(100)"`
    Type                string          `orm:"size(30)"`
    Admin               bool
    Car                 []*Car          `orm:"reverse(many)"`
}

Is there any way I can render a form directly using this structure? I think valid:required rakes care of validation, but how do we control form rendering.


Solution

  • In controller:

    func (this *AddController) Get() {
       this.Data["Form"] = & UserProfile{}
       this.TplNames = "index.tpl"
    

    }

    In template :

    <form action="" method="post">
        {{.Form | renderform}}
    </form>