2015-12-15 27 views
0

我使用燼Django的適配器作爲我的後端設計在Python/Django的。(http://dustinfarris.com/ember-django-adapter/的hasMany沒有更新燼店

feed.js(模型)

import DS from 'ember-data'; 

const {attr} = DS 

export default DS.Model.extend({ 
    gallery_name:attr('string'), 
    thumbnail_url:attr('string'), 
    is_following:attr('boolean'), 
    time:attr('string'), 
    description:attr('string'), 
    feedPhotos:DS.hasMany('feedPhoto',{embedded:'always'}) 
}); 

feedphoto.js(模型)

import DS from 'ember-data'; 

export default DS.Model.extend({ 
    feed: DS.belongsTo('feed'), 
    url: DS.attr(), 
    profilePic: DS.attr(), 
    userName: DS.attr(), 
    userKarma: DS.attr(), 
    caption: DS.attr(), 
    numComments: DS.attr(), 
    owner: DS.attr(), 
    time: DS.attr(), 
    photo_url: DS.attr(), 
    comments_url: DS.attr(), 
    numFives: DS.attr(), 
    fivers_url: DS.attr(), 
    fivers_pk: DS.attr(), 
    fullphoto_url: DS.attr(), 
    fullphoto_pk: DS.attr(), 
    is_fived: DS.attr('boolean'), 
    hiFiveKarma: DS.attr(), 
    owner_pk: DS.attr(), 
    userFirstName: DS.attr(), 
    is_bookmarked: DS.attr('boolean') 
}); 

feed.js(串行)

import DRFSerializer from './drf'; 
import DS from 'ember-data'; 

export default DRFSerializer.extend(DS.EmbeddedRecordsMixin,{ 
    primaryKey: 'pk', 
    attrs:{ 
    feedPhotos:{ embedded: 'always' } 
    } 
}); 

feedphoto.js(serailizer)

import DRFSerializer from './drf'; 
import DS from 'ember-data'; 

export default DRFSerializer.extend({ 
    primaryKey: 'pk', 
}); 

response.json

[{ 
    "pk": 127, 
    "url": "http://example.com/api/galleries/127/", 
    "gallery_name": "Faces", 
    "thumbnail_url": "https://dz.cloudfront.net/galleryThumbs/2656a05c-4ec7-3eea-8c5e-d8019454d443.jpg", 
    "time": "1 month ago", 
    "description": "Created by user", 
    "is_following": true, 
    "feedPhotos": [{ 
     "pk": 574, 
     "url": "http://examle.com/api/photos/574/", 
     "profilePic": "https://d3.cloudfront.net/userDPs/b6f69e4e-980d-3cc3-8b3e-3eb1a7f21350.jpg", 
     "userName": "Rohini", 
     "userKarma": 194, 
     "caption": "Life @ Myanmar!", 
     "numComments": 0, 
     "owner": "http://example.cloud.net/api/users/45/", 
     "time": "2 months ago", 
     "photo_url": "https://example.cloud.net/photos/eeae72d5-d6af-391e-a218-b442c0c7e34e.jpg", 
     "comments_url": "http://example.cloud.net/api/photos/574/comments/", 
     "numFives": 2, 
     "fivers_url": "http://example.cloud.net/api/photogalleries/1303/fivers/", 
     "fivers_pk": 1303, 
     "fullphoto_url": "http://example.cloud.net/api/photogalleries/1303/photo/", 
     "fullphoto_pk": 1303, 
     "is_fived": false, 
     "hiFiveKarma": 0, 
     "owner_pk": 45, 
     "userFirstName": "Rohini", 
     "is_bookmarked": false 
    }, { 
     "pk": 446, 
     "url": "http://example.cloud.net/api/photos/446/", 
     "profilePic": "https://example.cloud.net/userDPs/b359fab0-211d-32b5-8f13-f5edbeb0fbf9.jpg", 
     "userName": "Shushma", 
     "userKarma": 224, 
     "caption": "", 
     "numComments": 0, 
     "owner": "http://example.cloud.net/api/users/34/", 
     "time": "2 months ago", 
     "photo_url": "https://example.cloud.net/photos/a415ed45-b6e5-33e0-a17e-6452ddb2f258.jpg", 
     "comments_url": "http://example.cloud.net/api/photos/446/comments/", 
     "numFives": 3, 
     "fivers_url": "http://example.cloud.net/api/photogalleries/1315/fivers/", 
     "fivers_pk": 1315, 
     "fullphoto_url": "http://example.cloud.net/api/photogalleries/1315/photo/", 
     "fullphoto_pk": 1315, 
     "is_fived": false, 
     "hiFiveKarma": 0, 
     "owner_pk": 34, 
     "userFirstName": "Shushma", 
     "is_bookmarked": false 
    }] 
}] 

的代碼能夠節省飼料模型的細節,但不是feedphoto model.In我燼檢查飼料模型顯示正確的data.But feedphoto模型沒有顯示任何數據。我不知道爲什麼我錯了。

回答

0

我認爲你有兩個問題

  1. 在大寫字母:DS.hasMany('feedPhoto',{embedded:'always'})。 這意味着,您的模型文件應該被命名爲'feed-photo.js'或'feed_photo.js'。
  2. 此外,我還沒有使用過ember-django-adaptor,但他們通常會將feed_photos解釋爲feedPhoto作爲響應的一個響應。因此,您應該可以從服務器返回feed_photos而不是feedPhotos或將該屬性重命名爲feedphotos