toranb / ember-data-django-rest-adapter

An ember-data adapter for django web applications powered by the django-rest-framework
MIT License
152 stars 26 forks source link

Enable readOnly attributes and partial sends as PATCH #82

Closed kitsunde closed 10 years ago

kitsunde commented 10 years ago

It's because djangorestframework changes the expected method if we send back a partial update from PUT to PATCH. Which means a simple attribute serialization override.

App.UserSerializer = DS.DjangoRESTSerializer.extend({
  serialize: function(record, options) {
    var json = this._super.apply(this, arguments);
    delete json.profile_picture;
    return json;
  }
});

Fails.

Instead adding support for readOnly attributes proposed but not (yet) implemented in https://github.com/emberjs/data/pull/303

App.User = DS.Model.extend({
  username: DS.attr('string'),
  profile_picture: DS.attr('string', {readOnly: true}),
});

Would serialize the model without the profile_picture attribute and send it as a PATCH.

I could also submit a pull request to have django-rest-adapter only send across data that has changed, rather than the whole model, in a similar fashion.

toranb commented 10 years ago

Wow! excellent work on this! what version of DRF did this PATCH support change like you mentioned? I must be behind a few releases (or did I simply miss this altogether)

kitsunde commented 10 years ago

@toranb It has had support for it since 2.1.15 in January last year according to the release notes: http://www.django-rest-framework.org/topics/release-notes

toranb commented 10 years ago

Merge when you are ready my friend -I've added you as a full time contributor :)

dustinfarris commented 10 years ago

@Celc what is the status on this?

kitsunde commented 10 years ago

I need to rebase on latest when I have some time over. It doesn't merge cleanly right now. Otherwise It should be good to go.

11 jul 2014 kl. 03:18 skrev Dustin Farris notifications@github.com:

@Celc what is the status on this?

— Reply to this email directly or view it on GitHub.

dustinfarris commented 10 years ago

@Celc master is 2-space indentation now. Can you rebase?

kitsunde commented 10 years ago

I'll fix this when I have enough time to spare, work a bit hectic atm. :)

22 jul 2014 kl. 23:52 skrev Dustin Farris notifications@github.com:

@Celc I just switched everything to 2-space indentation. Can you rebase?

— Reply to this email directly or view it on GitHub.

dustinfarris commented 10 years ago

@Celc totally understand. Let me know if you think you won't be able to get to it.

dustinfarris commented 10 years ago

Closing in favor of #97.