5099 Posts in 1519 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 294 Views |
-
ModelAdmin Relations

28 September 2011 at 10:43pm
Hi,
i have a DataObject which is managed by ModelAdmin via the cms, so far so good. But all objects that are related to this with a $has_one relation are only shown as DropDownField with the id. How can i customize this to change the DrowDown to other fields from the managed object?
Thanks a lot for your help!
mark
-
Re: ModelAdmin Relations

28 September 2011 at 11:36pm
Hi Mark,
Welcome to the forums!
I'm not sure what you mean by "How can i customize this to change the DrowDown to other fields from the managed object". Since this is a relationship within the datamodel you are restricted to what can be used... the option I think that might help is the ItemPicker...
https://github.com/ajshort/silverstripe-itemsetfield
Also in the situation I what the information edittable after it has been selected I use this...
http://www.silverstripe.org/data-model-questions/show/13089#post295584Hope this helps
Barry
-
Re: ModelAdmin Relations

29 September 2011 at 12:07am
Thanks for your quick reply!
To clarify it a bit, i have made a screenshot where you can see two DropDownFields with only an id from the relation in it. And i want to change this to another field from the related object.
mark
-
Re: ModelAdmin Relations

29 September 2011 at 12:19am
Ahhh....
Where the system is trying to scaffold the drop down it looks for a "Name" field. If you add that then it will look a bit better.
Alternatively - you could redraw the drop down with the right "Name" (within getCMSFields)
$dos = DataObject::get($strDataObjectName);
$map = $dos ? $dos->toDropdownMap('ID','Name') : array(); //change Name in this line
$fields->replaceField('HasOneID',new DropdownField('HasOneID','Label',$map)); -
Re: ModelAdmin Relations

29 September 2011 at 12:41am
Thanks a lot, it works great!
I had already found the replaceField method but now it ist clear to me how to use it!
mark
| 294 Views | ||
|
Page:
1
|
Go to Top |


