-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date and DateTime Transforms (WIP) #61
Comments
Hi @toranb, is it related with the error |
What do your models look like when you get this error? |
@toranb it looks alright here. I'm trying to save the follow model but I'm having issues with class Board(models.Model):
title = models.CharField(max_length=200, blank=True)
body = models.TextField(blank=True)
image = models.ImageField(upload_to='upload/images/boards', max_length=200, blank=True)
pub_date = models.DateTimeField('date published') I've created a gist with the full model and JavaScript https://gist.github.com/henriquea/9914529. Am I missing something? |
Excellent - you are correct. In your ember model for this do the following App.Board = DS.Model.extend({
pubDate: attr('isodatetime')
}); Then you need to setup / register the isodatetime transform so it works with ember and django DS.IsodatetimeTransform = DS.Transform.extend({
deserialize: function(serialized) {
var type = typeof serialized;
if (type === "string") {
return new Date(Ember.Date.parse(serialized));
} else if (type === "number") {
return new Date(serialized);
} else if (serialized === null || serialized === undefined) {
// if the value is not present in the data,
// return undefined, not null.
return serialized;
} else {
return null;
}
},
serialize: function(date) {
if (date instanceof Date && date.toString() !== 'Invalid Date') {
return date.toJSON();
} else {
return null;
}
}
});
Ember.Application.initializer({
name: "DjangoRESTAdaptertransforms",
after: "transforms",
initialize: function(container, application) {
application.register('transform:isodatetime', DS.IsodatetimeTransform);
}
}); Let me know if this gets you moving. This is what I'm doing in my commercial app today |
I did this but was missing the 'attr' isodate. Thanks @toranb |
Any news on when this gets merged into a release? |
@valberg honestly if you wanted to submit a PR that has this included (and throw a few tests into show how it works when a xhr is fired off) I'd pull it in. For better or worse I don't work with ember day-to-day anymore so I'm not sure if the community needs or wants this /how it might impact other using the library in production today |
I am not qualified to write a PR, but FWIW I do need this functionality and the workaround does the job for me. |
Thanks for the feedback @dbinetti. We will get this into the next release. |
great! and while I’m asking for free stuff what about pagination? :-P On Wed, Jul 16, 2014 at 12:41 PM, Dustin Farris [email protected]
|
@dbinetti there is an ongoing conversation in #80. tl;dr we are waiting on Ember 1.7 stable which should support queryParams, making pagination a lot more straight-forward. |
yep, makes sense. looking forward to that as well! many thanks. On Wed, Jul 16, 2014 at 12:48 PM, Dustin Farris [email protected]
|
Closing in favor of #96. |
Currently you need to manually wire up date and datetime to work with DRF (the below is a workaround that works with the current build). I plan to include this in a future release (need to get some testing around this before adding it directly to the adapter)
Ignore the duplication for the moment
The text was updated successfully, but these errors were encountered: