[Answered ]-Django Rest/Ember How to connect to models

2👍

Without going into a ton of detail, I’ve created a mini example of what you’re looking for

http://emberjs.jsbin.com/Ozimatuj/2/edit

You’ll note that I’m using mockjax, so instead of hitting any real endpoint, it’s all mocked. Additionally I’d recommend using a client side record management solution (such as ember-data or ember-model). That’s another discussion though.

In the application route (which correlates with the root of your app) it hits the model hook (which should return the model associated with that route. I’m returning a POJO of the users. That model is being assigned as the content of the application controller (automatically generated). The the application template is being built, and it’s being backed by the application controller. Inside the application template we create an instance of ember select, and we tell it that the content backing it is model (which is the model/content in the application controller). We also say, use bind the user model (you could do id) and the name to the value and the label respectively.

I then bound the value of the select to selectedPerson, so anytime the value changes, the selectedPerson updates, the template which talks about that person will update. Magic. Ember does the rest.

This is a really broad question, so if you have any other questions, please ask a specific question, and I’d really recommend going through the getting started guide, it’s really short, but will give you a decent foundation of terminology and methodology of Ember. http://emberjs.com/guides/getting-started/

For Ember Data I’d do a quick read the of the transition document for ED 1.0 beta.
https://github.com/emberjs/data/blob/master/TRANSITION.md

DS.DjangoRESTSerializer = DS.RESTSerializer.extend();
DS.DjangoRESTAdapter = DS.RESTAdapter.extend({
  defaultSerializer: "DS/djangoREST"
});

Leave a comment