Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

ModelAdmin and Many to Many


Reply


2 Posts   1580 Views

Avatar
amacgregor

Community Member, 1 Post

15 February 2009 at 8:03am

Edited: 16/02/2009 7:31am

Hi,

I have been working with the ModelAdmin for a few days now and it works beatifully with the exception of many to many relationships; so any help fixing or working around this will be awesome

Model Admin class

class PortfolioAdmin extends ModelAdmin {

protected static $managed_models = array(
'Project',
'Category',
'Client',
'Technology'
);

static $url_segment = 'projects'; // will be linked as /admin/products
static $menu_title = 'Portfolio Admin';

}

Project class

class Project extends DataObject {

static $db = array(
'Name' => 'Varchar',
'ProjectCode' => 'Varchar',
'Description' => 'Text',
'Budget' => 'Currency'
);

static $many_many = array(
'Category' => 'Category',
'Technology' => 'Technology'
);

static $has_one = array(
'Client' => 'Client'
);

static $searchable_fields = array(
'Name',
'ProjectCode'
);

}

Category class

class Category extends DataObject {
static $db = array(
'Title' => 'Text',
'Description' => 'Text'
);
static $belongs_many_many = array(
'Project' => 'Project'
);
}


Technology Class

class Technology extends DataObject {
static $db = array(
      'TechName' => 'Varchar',
      'TechVersion' => 'Varchar',
      'Description' => 'Text'
);
static $belongs_many_many = array(
'Project' => 'Project'
);
}

Client class

class Client extends DataObject{

   static $db = array(
      'Title' => 'Varchar',
      'Company' => 'Varchar',
      'ContactName' => 'Varchar',
      'Webpage' => 'Varchar',
      'Email' => 'Varchar'
   );
   static $has_one = array(
   );
   static $field_names = array(
      'Title' => 'Title'
   );
static $searchable_fields = array(
'Title',
'Email'
);

}

Avatar
rbquirke

Community Member, 70 Posts

16 February 2009 at 2:08pm

what problem are you having exactly?