Git Product home page Git Product logo

Comments (16)

ewilson avatar ewilson commented on July 24, 2024 3

I tried new Date().toJSON().slice(0, 10), and that works. Seems a reasonable workaround.

from ember-django-adapter.

ewilson avatar ewilson commented on July 24, 2024

It seems that the issue is that I am only storing a date in the backend. The date is defined in my model as follows:

event_date = models.DateField(default=date.today)

If I replace this with

event_date = models.DateTimeField(default=datetime.now)

then everything works as expected. Nevertheless, I'd like it if the adapter/DRF could convert the JS Date object to the appropriate day. However, I can imagine that this is simply beyond what the adapter can reasonably do. (How could it know that the API only wants a date?)

Having thought it through, my guess is that there is no way for the adapter to solve my problem. Feel free to close. Comments are welcome.

from ember-django-adapter.

ewilson avatar ewilson commented on July 24, 2024

OK, I was too quick. It turns out that in the DateTimeField case, the API does not return 400, but it does not record the date field at all. So my workaround doesn't work actually. Whether the back-end expects a DateField or a DateTimeField it doesn't quite work. In the first case the POST returns 400. In the second case it is 200, but is silently unsuccessful.

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

The adapter should work with both DateField and DateTimeField without too much headache. I am looking into this.

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

@ewilson this is still on my todo list. currently battling some dev issues with ember-cli and bower

from ember-django-adapter.

ewilson avatar ewilson commented on July 24, 2024

@dustinfarris No worries, its not a blocker for my toy project. I appreciate what you are doing.

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

I've confirmed this bug. Basically, Ember has one notion of datetime, whereas Django has date and datetime. Ember Data's DateTransform sends a full ISO-8601 datetime value for everything, and DRF blows up if the model's field is a DateField (as opposed to a DateTimeField).

Personally, I think this is a bug in DRF, or at least a deficiency. We will either need to open a PR with DRF (that may or may not get accepted), or add custom date and datetime transforms to the adapter library that can be imported as needed by EDA users.

I'm open to opinions on which way is best, but I'm thinking the custom transforms would be nice quick fix for now.

/cc @benkonrath

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

It looks like the folks over at DRF already gave this some thought: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/fields.py#L920-L922

from ember-django-adapter.

StErMi avatar StErMi commented on July 24, 2024

Hi I'm using AngularJS and AngularJS Bootstrap UI and the date returned by the JS datepicker is failing with the same error.

On Django the model field is

date_of_birth = models.DateField(null=True, blank=True)

and when I pass it via POST the date is like this

u'1987-09-03T00:00:00.000Z'

but the serializer.is_valid() return that error

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

Hi @StErMi, I'm not sure if it's possible to override that in Angular, but as a workaround you can tell DRF to accept a different format. http://www.django-rest-framework.org/api-guide/settings/#date-and-time-formatting

from ember-django-adapter.

StErMi avatar StErMi commented on July 24, 2024

What I'm passing inside the POST is the ISO-8601 standard representation of a Javascript date.
It's pretty strange that DRF is not parsing it correctly.

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

Yeah, DRF will process that just fine for DateTimeField, but not for DateField.

from ember-django-adapter.

StErMi avatar StErMi commented on July 24, 2024

Is it a bug? Should we report it?

On Tue, Feb 10, 2015 at 7:10 PM, Dustin Farris [email protected]
wrote:

Yeah, DRF will process that just fine for DateTimeField, but not for
DateField.


Reply to this email directly or view it on GitHub
#47 (comment)
.

Founder e CEO di SurveyLab
https://surveylab.me/Android Engineer @ musiXmatch
http://www.musixmatch.com/

Skype: e.ricci.designfuture
Twitter: @StErMi https://twitter.com/stermi
Linkedin: https://www.linkedin.com/in/emanuelericci
Google+: https://plus.google.com/u/0/+EmanueleRicci/posts
Hangout: [email protected]

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

No, it's a design decision. See the link I posted—DRF is explicit about the formats that are accepted, but you can change them in your settings if you need to.

from ember-django-adapter.

dustinfarris avatar dustinfarris commented on July 24, 2024

@ewilson thanks. That sounds like a candidate for a "date" transform.

from ember-django-adapter.

ariouss avatar ariouss commented on July 24, 2024

Hello im use reactjs for front-end and django rest framework for back-end and i want react just send date to backend but i dont know how can i do that ? and my datepicker jost input date but react send datetime for backend. any solution ?

from ember-django-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.