Re: Having trouble understanding Timezone

2016-01-06 Thread Mike Dewhirst

Ryan

I too went through USE_TZ and time zones etc but too long ago to 
remember enough to answer your questions with any authority. However 
this works for me ...


USE_TZ = True
TIME_ZONE = 'UTC'

At 18:23 (AESummertime) here in Melbourne Australia I just created a new 
record in my Postgres 9.3 database. FWIW the Ubuntu 12.04 database 
server runs on local time. I'm using a Windows 8.1 client and Django 
1.8.8 dev server.


The model save() method fills in a datetime field if it is blank. It 
uses my when() utility. See below.


Examining the new record in the database the date/time saved is ...

2016-01-07 18:23:53.710608+11

There is enough information there to represent a UTC time. Simply 
subtract 11 hours. Then add whatever for another timezone. I don't know 
if the Django framework does that automatically based on the client 
system time but I'm not too concerned about that. I only care that we 
are are not losing date/time data.


My when() utility was called by save() without argument. It goes like 
this ...


def when(days=0):
"""Function to return a non-naive datetime."""
dday = datetime.now(tz=pytz.utc)
if days == 0:
return dday
ttime = datetime.time(dday)
return timezone.make_aware(datetime.combine(
datetime.fromordinal(dday.toordinal() + days), ttime), pytz.utc)

HTH

Mike


On 7/01/2016 2:36 PM, Ryan Causey wrote:

Hello,

I'm new to Python and Django so please bear with me on this one.

I've been reading the Django docs, googling, and searching this mailing
list on the proper configuration and usage of Django when USE_TZ = True.
However, I'm still a bit fuzzy on things and would like clarification on
the following:

 1. The documentation says that when USE_TZ = True that "Django stores
datetime information in UTC in the database, uses time-zone-aware
datetime objects internally, and translates them to the end user’s
time zone in templates and forms." Does this mean that the TIME_ZONE
setting in settings.py should be UTC? Or should it be the timezone
in which the database server is located?
 2. I am using a postgresql database, and the installation defaulted the
database's timezone to my local one. In support of Django storing
all datetime information in UTC in the database, does the database's
timezone needs to be set to UTC? Or is it correct for the database's
timezone to be the local one?
 3. The documentation also says that one should use the UTC timezone in
the code, and only convert to local time when dealing with end
users. I take this to mean that in any code I write I should set
tzinfo = UTC for all datetime objects I create programmatically and
let Django translate them in forms and views to the end user's
timezone automatically. Is this correct?

Thank you in advance for the help,

-Ryan Causey

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b37291e8-3d99-49a4-8e9a-13a6639ef29b%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/568E1483.1010404%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


404, media files are not served in template during development

2016-01-06 Thread charito.romeo
Hi ALL, 


I was trying to render user-uploaded media files into the template but it 
 throws out a 404 only on the media files. The all other context variables 
are rendered except the media files. I am using django 1.9.1 and python 
2.7.9.


Here's the  settings file. I only included the code relevant to the current 
issue.

settings.py

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pi_app',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',


TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS':[os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',

],
},
},
]



STATIC_URL = '/static/'

STATIC_PATH = (os.path.join(BASE_DIR, 'static'),
   '/var/www/static/',)

STATICFILES_DIRS = (
STATIC_PATH,
)
MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


Here's is my urls.py

from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static

 
from . import views

urlpatterns = [
url(r'^$', views.UserMainView.as_view(), name='index'),
url(r'^upload_file/$', views.upload_file, name='upload_file'),
url(r'^video_entry/(?P[\w-]+)/$', views.video_entry, 
name='video_entry'),


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


Here is my views.py

def video_entry( request, video_slug):
video_details = Entry.objects.get(slug = video_slug)
context = {'video_details': video_details}
context['presentation_video']= video_details.video




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f33e0c1e-8001-49b2-996d-52dd1c1b36bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Having trouble understanding Timezone

2016-01-06 Thread Avraham Serour
1. you don't need to st the TIME_ZONE setting, leave at default
2. honestly I don't know how setting the timezone in postgres influences
the data, but I believe it doesn't need to be in sync with django settings.
3. yes, this is a good recommendation

success
Avraham

On Thu, Jan 7, 2016 at 5:36 AM, Ryan Causey  wrote:

> Hello,
>
> I'm new to Python and Django so please bear with me on this one.
>
> I've been reading the Django docs, googling, and searching this mailing
> list on the proper configuration and usage of Django when USE_TZ = True.
> However, I'm still a bit fuzzy on things and would like clarification on
> the following:
>
>
>1. The documentation says that when USE_TZ = True that "Django stores
>datetime information in UTC in the database, uses time-zone-aware datetime
>objects internally, and translates them to the end user’s time zone in
>templates and forms." Does this mean that the TIME_ZONE setting in
>settings.py should be UTC? Or should it be the timezone in which the
>database server is located?
>2. I am using a postgresql database, and the installation defaulted
>the database's timezone to my local one. In support of Django storing all
>datetime information in UTC in the database, does the database's timezone
>needs to be set to UTC? Or is it correct for the database's timezone to be
>the local one?
>3. The documentation also says that one should use the UTC timezone in
>the code, and only convert to local time when dealing with end users. I
>take this to mean that in any code I write I should set tzinfo = UTC for
>all datetime objects I create programmatically and let Django translate
>them in forms and views to the end user's timezone automatically. Is this
>correct?
>
> Thank you in advance for the help,
>
> -Ryan Causey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b37291e8-3d99-49a4-8e9a-13a6639ef29b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tKGe87kY4rRc33Rjtd1TdXvnh7-zeBaEsj0-T1ss7AaRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


passing list of objects as manytomany field type in django

2016-01-06 Thread Akash Tomar


I want to know if we can pass a list of objects (in this case list of blog 
objects to the Entry model as the manytomany object parameter). On doing so 
i am not getting the desired result. Please help.

models.py

class Blog(models.Model):
id=models.AutoField(primary_key=True)
class Entry(models.Model):
id=models.AutoField(primary_key=True)
blogs=models.ManyToManyField(Blog)

views.py

def something(request):
list=[]
for i in range(10):
list.append(Blog.objects.get(pk=i))
ans=Entry.objects.filter(blogs=list)
print(ans)
#some other work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87b878aa-da70-454f-98fb-035d1222c266%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Having trouble understanding Timezone

2016-01-06 Thread Ryan Causey
Hello,

I'm new to Python and Django so please bear with me on this one.

I've been reading the Django docs, googling, and searching this mailing 
list on the proper configuration and usage of Django when USE_TZ = True. 
However, I'm still a bit fuzzy on things and would like clarification on 
the following:


   1. The documentation says that when USE_TZ = True that "Django stores 
   datetime information in UTC in the database, uses time-zone-aware datetime 
   objects internally, and translates them to the end user’s time zone in 
   templates and forms." Does this mean that the TIME_ZONE setting in 
   settings.py should be UTC? Or should it be the timezone in which the 
   database server is located?
   2. I am using a postgresql database, and the installation defaulted the 
   database's timezone to my local one. In support of Django storing all 
   datetime information in UTC in the database, does the database's timezone 
   needs to be set to UTC? Or is it correct for the database's timezone to be 
   the local one?
   3. The documentation also says that one should use the UTC timezone in 
   the code, and only convert to local time when dealing with end users. I 
   take this to mean that in any code I write I should set tzinfo = UTC for 
   all datetime objects I create programmatically and let Django translate 
   them in forms and views to the end user's timezone automatically. Is this 
   correct?

Thank you in advance for the help,

-Ryan Causey

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b37291e8-3d99-49a4-8e9a-13a6639ef29b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Working with Django signals

2016-01-06 Thread Bernardo Garcia
Hi luisza

I've choose work overriding the  save() method of the  AbstractUser class, 
instead of apply the  post_save() signal to the  create_profile_for_new_use
 function.

According to the prevouos mentioned, my  User MedicalProfile, PatientProfile
 y PhisiotherapystProfile models stayed so:

from __future__ import unicode_literalsfrom django.conf import settingsfrom 
django.contrib.auth.models import AbstractUserfrom django.db import modelsfrom 
django.template.defaultfilters import slugifyfrom django.dispatch import 
receiverfrom django.db.models.signals import post_save
class User(AbstractUser):
is_medical = models.BooleanField(default=False)
is_physiotherapist = models.BooleanField(default=False)
is_patient = models.BooleanField(default=False)
slug = models.SlugField(max_length=100, blank=True)
photo = models.ImageField(upload_to='avatars', null = True, blank = True)

def save(self, *args, **kwargs):
user = super(User, self).save( *args, **kwargs)

# Creating and user with medical, patient and physiotherapist profiles
if self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists()\
and self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
patient_profile=PatientProfile(user=self).save()
physiotherapist_profile=PhysiotherapistProfile(user=self).save()
#profile.save()

# Creating and user with medical and patient profiles
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
patient_profile=PatientProfile(user=self).save()

# Creating and user with medical and physiotherapist profiles
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
physiotherapist_profile=PhysiotherapistProfile(user=self).save()

# Creating and user with physiotherapist and patient profiles
elif self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():

physiotherapist_profile = PhysiotherapistProfile(user=self).save()
patient_profile = PatientProfile(user=self).save()

# Creating and user with medical profile
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists():
profile = MedicalProfile(user=self)
profile.save()

# Creating and user with patient profile
elif self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():
profile = PatientProfile(user=self)
profile.save()

# Creating and user with physiotherapist profiles
elif self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():
profile = PhysiotherapistProfile(user=self)
profile.save()



# We get the profiles user according with their type
def get_medical_profile(self):
medical_profile = None
if hasattr(self, 'medicalprofile'):
medical_profile=self.medicalprofile
return medical_profile

def get_patient_profile(self):
patient_profile = None
if hasattr(self, 'patientprofile'):
patient_profile = self.patientprofile
return patient_profile

def get_physiotherapist_profile(self):
physiotherapist_profile = None
if hasattr(self, 'physiotherapistprofile'):
physiotherapist_profile = self.physiotherapistprofile
return physiotherapist_profile

# We redefine the attributes (create db_table attribute) in class Meta to 
say to Django
# that users will save in the same table that the Django default user model
# 
https://github.com/django/django/blob/master/django/contrib/auth/models.py#L343
class Meta:

db_table = 'auth_user'
class MedicalProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PatientProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PhysiotherapistProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 

Re: Choice and choice

2016-01-06 Thread Mario R. Osorio
Choice is a class and choice is an instance of that class.

You might want to check your knowledge of python before trying django...


On Wednesday, January 6, 2016 at 8:07:16 AM UTC-5, 林攀 wrote:
>
>
> dear:
>  in djano the first app   what is difference between Choice   and 
> choice ? I feel confused!
>
>
>
> --
> *林攀*
>
>
> 新的一年,让我陪你奋斗,让我陪你辛苦!-2016携手前行>> 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48b93f91-56d7-42d8-b7f7-a878fab1835a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Amazon + Django each 12 hours appears that [Errno 5] Input/output error

2016-01-06 Thread Bernardo Garcia




I recently setup and deploy an Amazon EC2 instance for deploy my django 
project.

I  was interacting with my application via browser when I get this error in 
the browser:


errno 5 input/output error django 


This error did reference to some function of my application, but in my 
console the server require restart and when I did this, the error was 
solved of a magic way ..


I've search this error and I found this ticket 
reported https://code.djangoproject.com/ticket/23284


This report is very similar to my error ...

Although I don't know if this error back inside 12 hours, I restart my 
server and this was solved and now all it's work O.K.



When one bug is declared as invalid in Django 


What does it mean? 


There is some problem with EC2 infraestructure with Django (I don't think 
so) or the problem is more for my application side?


Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69701d06-2bb3-439f-b2bb-81ff67a21f43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Conditional annotation super slow

2016-01-06 Thread Simon Charette
Hi Mark,

I suppose you opened #26045  
about the same issue.

Are you using PostgreSQL? If it's the case the issue I suppose the issue is 
fixed 
in Django 1.9 

.

Simon

Le mercredi 6 janvier 2016 08:36:36 UTC-5, Mark a écrit :
>
> I've run query manually removing all fields from GROUP BY that are not 
> related to aggregation and query runs fast. But how to do the same in 
> Django? How to remove unrelated fields to the aggregation from GROUP BY 
> clause?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85cb606d-6fe0-4b75-bbfa-33f016661e69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while loading data from fixture

2016-01-06 Thread Parijatha Kumar Pasupuleti
I've posted this question in stackoverflow at 
http://stackoverflow.com/questions/34636107/error-while-loading-data-from-fixture.
 
The solution was posted by one Alasdair. For reference, his answer is 
pasted below ...

"

The natural_key 

 
method should return a tuple, not a string.

def natural_key(self):
return (self.name,)

If natural_key is a string "Andaman and Nicobar" instead of a tuple ('Andaman 
and Nicobar',) then *natural_key will unpack each of the 19 characters in 
the string as a separate argument. Along with self, that gives you 20 
arguments from your error message.
"





On Wednesday, 6 January 2016 19:59:09 UTC+5:30, Parijatha Kumar Pasupuleti 
wrote:
>
> Hai !
>
> I have the following model and manager.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class StateManager(models.Manager):def get_by_natural_key(self, 
> name):return self.get(name=name)class State(models.Model):class 
> Meta:verbose_name = "State"verbose_name_plural = 
> "States"permissions = (('access_state', 'Can access 
> States'),)COUNTRIES = (('India', 'India'),
> ('USA', 'USA'),('Thailand', 'Thailand'),)# Managers
> objects = StateManager()# Database fieldsname = 
> models.CharField('Name',max_length=100,
> unique=True,help_text='''100 chars max''')
> code = models.CharField('Code',max_length=10,
> unique=True,help_text='''10 chars max''',
> null=True, blank=True)country = models.CharField(
> max_length=50,default="India",choices=COUNTRIES,
> blank=False,null=False)def __str__(self):return 
> self.name def natural_key(self):return 
> self.name *
>
> --
>
> My fixture file is given below 
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *[{"model": "parties.state","fields": {"name": "Andaman 
> and Nicobar","code": "AN","country": "India"}},{
> "model": "parties.state","fields": {"name": "Andhra 
> Pradesh","code": "AP","country": "India"}},{
> "model": "parties.state","fields": {"name": "Arunachal 
> Pradesh","code": "AR","country": "India"}},{
> "model": "parties.state","fields": {"name": "Assam",
> "code": "AS","country": "India"}},{"model": 
> "parties.state","fields": {"name": "Bihar","code": 
> "BR","country": "India"}},{"model": "parties.state",
> "fields": {"name": "Chandigarh","code": "CH",
> "country": "India"}},{"model": "parties.state","fields": 
> {"name": "Chhattisgarh","code": "CG","country": 
> "India"}},{"model": "parties.state","fields": {"name": 
> "Dadra and Nagar Haveli","code": "DN","country": "India"
> }},{"model": "parties.state","fields": {"name": "Daman and 
> Diu","code": "DD","country": "India"}},{"model": 
> "parties.state","fields": {"name": "Delhi","code": 
> "DL","country": "India"}},{"model": "parties.state",
> "fields": {"name": "Goa","code": "GA","country": 
> "India"}},{"model": "parties.state","fields": {"name": 
> "Gujarat","code": "GJ","country": "India"}},{
> "model": "parties.state","fields": {"name": "Haryana",
> "code": "HR","country": "India"}},{"model": 
> "parties.state","fields": {"name": "Himachal Pradesh",
> "code": "HP","country": "India"}},{"model": 
> "parties.state","fields": {"name": "Jammu and Kashmir",
> "code": "JK","country": "India"}},{"model": 
> "parties.state","fields": {"name": "Jharkhand","code": 
> "JH","country": "India"}},{"model": "parties.state",
> "fields": {"name": 

Re: Update model field after a certain period

2016-01-06 Thread 'Tom Evans' via Django users
On Wed, Jan 6, 2016 at 9:39 AM,   wrote:
> I have a Django model with a Boolean field called New. During the model
> creation it's set to True, but I want it to be updated automatically to
> False after a certain period (1 month post creation for example). Can I use
> signals here?

Another option is to replace the field with a "created" date time, and
add a computed property called "new" that tests to see whether it is
old or not.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2B8AJYJbeq9Z4VgBH%3DQcLTY17dhJg6gCfVRDfVnaf9evg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update model field after a certain period

2016-01-06 Thread Mark Harley
One option would be to create a custom management command 
(https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/) 
that checks for models with a `created_at < now - 1month`. You could then 
run this, say once a day, using crontab 
(https://help.ubuntu.com/community/CronHowto). Here created_at is a 
`datetime` field with `auto_now_add=True`.

On Wednesday, 6 January 2016 13:07:30 UTC, salma.ess...@gmail.com wrote:
>
> I have a Django model with a Boolean field called New. During the model 
> creation it's set to True, but I want it to be updated automatically to 
> False after a certain period (1 month post creation for example). Can I use 
> signals here?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b88f2d50-b3ea-4102-aeeb-de5d41979aa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Error while loading data from fixture

2016-01-06 Thread Parijatha Kumar Pasupuleti
Hai !

I have the following model and manager.
























































*class StateManager(models.Manager):def get_by_natural_key(self, 
name):return self.get(name=name)class State(models.Model):class 
Meta:verbose_name = "State"verbose_name_plural = 
"States"permissions = (('access_state', 'Can access 
States'),)COUNTRIES = (('India', 'India'),
('USA', 'USA'),('Thailand', 'Thailand'),)# Managers
objects = StateManager()# Database fieldsname = 
models.CharField('Name',max_length=100,
unique=True,help_text='''100 chars max''')
code = models.CharField('Code',max_length=10,
unique=True,help_text='''10 chars max''',
null=True, blank=True)country = models.CharField(
max_length=50,default="India",choices=COUNTRIES,
blank=False,null=False)def __str__(self):return 
self.namedef natural_key(self):return self.name*
--

My fixture file is given below 


































































































































































































































































































*[{"model": "parties.state","fields": {"name": "Andaman and 
Nicobar","code": "AN","country": "India"}},{
"model": "parties.state","fields": {"name": "Andhra 
Pradesh","code": "AP","country": "India"}},{
"model": "parties.state","fields": {"name": "Arunachal 
Pradesh","code": "AR","country": "India"}},{
"model": "parties.state","fields": {"name": "Assam",
"code": "AS","country": "India"}},{"model": 
"parties.state","fields": {"name": "Bihar","code": 
"BR","country": "India"}},{"model": "parties.state",
"fields": {"name": "Chandigarh","code": "CH",
"country": "India"}},{"model": "parties.state","fields": 
{"name": "Chhattisgarh","code": "CG","country": 
"India"}},{"model": "parties.state","fields": {"name": 
"Dadra and Nagar Haveli","code": "DN","country": "India"
}},{"model": "parties.state","fields": {"name": "Daman and 
Diu","code": "DD","country": "India"}},{"model": 
"parties.state","fields": {"name": "Delhi","code": 
"DL","country": "India"}},{"model": "parties.state",
"fields": {"name": "Goa","code": "GA","country": 
"India"}},{"model": "parties.state","fields": {"name": 
"Gujarat","code": "GJ","country": "India"}},{
"model": "parties.state","fields": {"name": "Haryana",
"code": "HR","country": "India"}},{"model": 
"parties.state","fields": {"name": "Himachal Pradesh",
"code": "HP","country": "India"}},{"model": 
"parties.state","fields": {"name": "Jammu and Kashmir",
"code": "JK","country": "India"}},{"model": 
"parties.state","fields": {"name": "Jharkhand","code": 
"JH","country": "India"}},{"model": "parties.state",
"fields": {"name": "Karnataka","code": "KA",
"country": "India"}},{"model": "parties.state","fields": 
{"name": "Kerala","code": "KL","country": 
"India"}},{"model": "parties.state","fields": {"name": 
"Lakshdweep","code": "LD","country": "India"}},{
"model": "parties.state","fields": {"name": "Madhya 
Pradesh","code": "MP","country": "India"}},{
"model": "parties.state","fields": {"name": 
"Maharashtra","code": "MH","country": "India"}},{
"model": "parties.state","fields": {"name": "Manipur",
"code": "MN","country": "India"}},{"model": 
"parties.state","fields": {"name": "Meghalaya","code": 
"ML","country": "India"}},{"model": "parties.state",
"fields": {"name": "Mizoram","code": "MZ",
"country": "India"}},{"model": "parties.state","fields": 
{"name": "Nagaland","code": "NL","country": 
"India"}},{"model": "parties.state","fields": {"name": 
"Odisha (Orissa)","code": "OD","country": "India"
}},{"model": "parties.state","fields": 

Re: Steadman

2016-01-06 Thread Jon Atkinson
I've alerted Mark off-list.

--Jon

On Wed, Jan 6, 2016 at 1:02 PM, Avraham Serour  wrote:

> virus people, don't click the link
>
> On Wed, Jan 6, 2016 at 2:29 PM, Steadman  wrote:
>
>> Please find the attached document referred to the mail subject.
>>
>> Steadman.io 
>> Blog  | Podcasts  | Twitter
>>  | Facebook
>> 
>>
>> I do a *live podcast* every Monday night (8pm GMT) called the 2014 Show
>> . I'm always looking for guests. Shout if you
>> fancy sitting in the big Skype chair!
>>
>> Download / View 
>>
>> [image: Inline images 1] 
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAAcSLoM43EB_36hUtzhXX-YPGxRkv0o-i8Z9fH8aVPxXhgEEZw%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFWa6t%2BXaEz4iOOZ%3DYcKKA5KXMD541cDWNEmnsqgY3RTStQT8w%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO4CLk%3DhOMm5W3U0Wf%2B1YWn7kvC17C8X7x7pszC3NE%2BNFy%2Bn_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Conditional annotation super slow

2016-01-06 Thread Mark
I've run query manually removing all fields from GROUP BY that are not 
related to aggregation and query runs fast. But how to do the same in 
Django? How to remove unrelated fields to the aggregation from GROUP BY 
clause?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/036c16a6-d088-40f9-9ed2-67a28280bd7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


../manage.py makemessages -l zh_CN do not create file

2016-01-06 Thread nie_kl


I am using Django for a web app.Today I used command :

../manage.py makemessages -l zh_CN 

to create the .po file.But nothing hanppend without printing the

processing locale zh_CN

Why?In my settins.py,all things about I18N was set.

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)

Does anyone know how to deal?
Many thanks

 And

django-admin makemessages -l zh_CN

is still the same result.


My app is 'enterprise' and 'myauth'.


My directories structure is:

.├── Web├── captcha├── collected_static├── demo├── dict├── enterprise│   ├── 
migrations│   ├── static│   ├── templates│   ├── templatetags│   └── view├── 
locale├── logs├── myauth│   ├── form│   ├── locale│   ├── migrations│   ├── 
static│   ├── templates│   └── views├── static│   ├── bootstrap│   ├── d3│   
├── img│   ├── jquery│   └── nvd3└── templates


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a3957ec-0517-40c0-91de-5a5dc699c908%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Update model field after a certain period

2016-01-06 Thread salma . essalmani . wbc
I have a Django model with a Boolean field called New. During the model 
creation it's set to True, but I want it to be updated automatically to 
False after a certain period (1 month post creation for example). Can I use 
signals here?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8a56ab6-cf56-4330-a37d-096681b9ff1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Choice and choice

2016-01-06 Thread 林攀

dear:
 in djano the first app  what is difference between Choice   and choice 
? I feel confused!




--

林攀

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24d8983d.13fe.15215659cfb.Coremail.18610710105%40163.com.
For more options, visit https://groups.google.com/d/optout.


Re: Steadman

2016-01-06 Thread Avraham Serour
virus people, don't click the link

On Wed, Jan 6, 2016 at 2:29 PM, Steadman  wrote:

> Please find the attached document referred to the mail subject.
>
> Steadman.io 
> Blog  | Podcasts  | Twitter
>  | Facebook
> 
>
> I do a *live podcast* every Monday night (8pm GMT) called the 2014 Show
> . I'm always looking for guests. Shout if you
> fancy sitting in the big Skype chair!
>
> Download / View 
>
> [image: Inline images 1] 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAcSLoM43EB_36hUtzhXX-YPGxRkv0o-i8Z9fH8aVPxXhgEEZw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6t%2BXaEz4iOOZ%3DYcKKA5KXMD541cDWNEmnsqgY3RTStQT8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Conditional annotation super slow

2016-01-06 Thread Mark


I'm using django's (1.8.5) conditional annotation in order to add filtered 
data to each object dynamically. But the issue is that it's very slow on 
all machines I've tested it.

What it does is basically adds data to each user. How many messages they 
sent from provided date, how many messages have failed and how many 
messages they sent from yesterday. There is not much data. Just about 100 
users and each of them may have about 50 messages daily.


objects = self.get_queryset().annotate(sent_count=
Sum(
Case(When(messages__date_sent__gte=date_from, then=1)),
output_field=IntegerField()
),
error_count=
Sum(
Case(When(messages__status__iexact='error', then=1)),
output_field=IntegerField()
),
sent_yesterday=
Sum(
Case(When(messages__date_sent__gte=yesterday, then=1)),
output_field=IntegerField()
)
)


When checking a query, it takes up to 15 seconds to execute it. Am I doing 
something wrong or is conditional annotation not designed for things like 
this?


After looking at the generated query, it seems that Django is trying to 
GROUP BY by every available field in both models and their related models.. 
After adding prefetch_related to some related models, issue was fixed on 
one machine, but still persists on the second one. 


Is this a bug?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75d15495-9c66-4e3c-a153-912b220d9e35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Steadman

2016-01-06 Thread Steadman
Please find the attached document referred to the mail subject.

Steadman.io 
Blog  | Podcasts  | Twitter
 | Facebook


I do a *live podcast* every Monday night (8pm GMT) called the 2014 Show
. I'm always looking for guests. Shout if you fancy
sitting in the big Skype chair!

Download / View 

[image: Inline images 1] 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAcSLoM43EB_36hUtzhXX-YPGxRkv0o-i8Z9fH8aVPxXhgEEZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging Django with Debug set to False

2016-01-06 Thread Dheerendra Rathor
What I do is to log things in log files. All exceptions are logged in
error.log files and I've enabled admin mail which sends me an email
whenever there is an exception.
So basically logs and emails are quite helpful in debugging and makes it
smooth.

On Wed, 6 Jan 2016 at 10:20 Web Architect  wrote:

> Thanks all for the responses and I would certainly consider them for
> production level debugging. I understand that application level debugging
> could be achieved by various logging mechanisms or tools.
>
> But one of my main concern is the platform level debugging where in if
> anything goes wrong with any package. For example, recently when I had set
> DEBUG=False, the backend was throwing HTTP 500. I was completely clueless
> what was happening. After deep debugging in the code, I figured out that
> 'compress js' that was being used in templates - it seemed was not being
> supported when DEBUG=False. It took some time to figure this out. Had there
> been a log or some mechanism, debugging would have been lot easier and
> quicker.
>
> On Monday, January 4, 2016 at 11:03:26 PM UTC+5:30, Web Architect wrote:
>>
>> Hi,
>>
>> Is there a way to debug Django when DEBUG is set to False in settings.py
>> (for example on production)?
>>
>> The reason for asking the above is if we face any issue with DEBUG set to
>> False and if we need to debug.
>>
>> We are new to Django and we are building an ecommerce platform based on
>> Django.
>>
>> Would appreciate if anyone could help with the above?
>>
>> Thanks.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1550f31d-bcf7-430a-849f-f219e5ba3077%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAByqUgi3XW5pYp8x7gcfqTc8avJ0NJ8Mj8JKVhizH20cUzW4MQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.