Re: RuntimeWarning "DateTimeField received a naive datetime" with TIMESTAMP MySQL field

2012-11-16 Thread Sencha
Yes I'm aware of this, however I'm not generating the datetime objects, 
it's all coming from Django (hence me wondering whether or not it's a bug 
or not). All I need to do to replicate the bug is get the object from the 
db and then save is straight away; then warning appears.

Django abstracts away the difference between MySQL's datetime field and 
timestamp field, so it should work!


On Friday, 16 November 2012 17:31:44 UTC, Timster wrote:

> It's well-documented. Check out the Django documentation page on time 
> zones:
>
> https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/
>
> When time zone support is enabled, Django uses time-zone-aware datetime 
> objects. If your code creates datetime objects, they should be aware too. 
> In this mode, the example above becomes:
>
> import datetimefrom django.utils.timezone import utc
> now = datetime.datetime.utcnow().replace(tzinfo=utc)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Ai0Xql4hyGgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RuntimeWarning "DateTimeField received a naive datetime" with TIMESTAMP MySQL field

2012-11-16 Thread Sencha
I'm running into an issue with the use of the MySQL `TIMESTAMP` field 
compared to `DATETIME` field.

Django is run with timezone support and default timezone of `UTC`.

I have 2 fields in my MySQL table, one is type `DATETIME` and the other is 
`TIMESTAMP`. Both are set in the model as a `DateTimeField`. The data is 
already populated in this example.

When the data is loaded into the model by Django, I can see in the 
`DateTimeField`'s `get_prep_value` method that the `DATETIME` field value 
come through as:

datetime.datetime(2012, 11, 16, 16, 9, 25, tzinfo=)


and the `TIMESTAMP` comes through as:

datetime.datetime(2012, 11, 16, 15, 51, 32)


So the value from the timestamp MySQL field is coming through not initiated 
with the default timezone like the datetime field is.

This becomes a problem with re-saving the model, even after making no 
changes. The warning is being thrown up:

File 
"/Users/me/.virtualenvs/momento/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
 
line 809, in get_prep_value RuntimeWarning)
RuntimeWarning: DateTimeField received a naive datetime (2012-11-16 
15:51:32) while time zone support is active.


Is this a bug? Any recommendations how to overcome this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uPSy092r7fsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Prefetch related data when using raw()

2012-07-30 Thread Sencha
Oh, and list() was required ;-)

On Thursday, 26 July 2012 20:44:45 UTC+1, akaariai wrote:
>
> On 26 heinä, 19:12, Sencha  wrote: 
> > I want to prefetch related data (ideally through the 
> prefetch_related()method), however I need to use the 
> > raw() mapper method that will map a custom query (complicated table 
> joins 
> > to filter my query properly) to my model. However when I try this I get: 
> > 
> > AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related' 
> > 
> > Is there any way I can achieve the prefetching when using 
> > Model.objects.raw()? 
> > 
> > Many thanks! 
>
> There is no direct way. However, you could try this (completely 
> untested, and not part of public api): 
>
> from django.db.models.query import prefetch_related_objects 
> raw_qs = list(raw_qs) # this line maybe not needed... 
> prefetch_related_objects(raw_qs, ['a_related_lookup', 
> 'another_related_lookup', ...]) 
>
>  - Anssi 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/pokK8uRCCFcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Prefetch related data when using raw()

2012-07-30 Thread Sencha
That's absolutely perfect, works like a charm! Thank you very much for the 
insight.


On Thursday, 26 July 2012 20:44:45 UTC+1, akaariai wrote:
>
> On 26 heinä, 19:12, Sencha  wrote: 
> > I want to prefetch related data (ideally through the 
> prefetch_related()method), however I need to use the 
> > raw() mapper method that will map a custom query (complicated table 
> joins 
> > to filter my query properly) to my model. However when I try this I get: 
> > 
> > AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related' 
> > 
> > Is there any way I can achieve the prefetching when using 
> > Model.objects.raw()? 
> > 
> > Many thanks! 
>
> There is no direct way. However, you could try this (completely 
> untested, and not part of public api): 
>
> from django.db.models.query import prefetch_related_objects 
> raw_qs = list(raw_qs) # this line maybe not needed... 
> prefetch_related_objects(raw_qs, ['a_related_lookup', 
> 'another_related_lookup', ...]) 
>
>  - Anssi 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/XHw_hG4RdPcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Prefetch related data when using raw()

2012-07-26 Thread Sencha
I want to prefetch related data (ideally through the prefetch_related()method), 
however I need to use the 
raw() mapper method that will map a custom query (complicated table joins 
to filter my query properly) to my model. However when I try this I get:

AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related'

Is there any way I can achieve the prefetching when using 
Model.objects.raw()?

Many thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bUapwzqLvpgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.