DateTimeField always returns None

2014-07-04 Thread William Granli


I am trying to create a queryset for getting the values of a DateTimeField 
which is DATETIME in the DB.

The class in models.py:

class ChangeMetrics(models.Model):
id = models.IntegerField(primary_key=True)
file_id = models.ForeignKey(File, db_column = 'file_id')
version_id = models.ForeignKey(Version, db_column = 'version_id')
function_id = models.ForeignKey(Function, blank=True, db_column = 
'function_id')
date = models.DateTimeField(blank=True, null=True)
user = models.TextField(blank=True)
changed = models.IntegerField(blank=True, null=True)

The field in the SQL DB:

date DATETIME

The tuples are populated in the database and running SQL queries directly 
on the DB is working perfectly.

This is the queryset I am currently using in Django:

queryset = ChangeMetrics.objects.filter(~Q(changed=None), ~Q(date=None), 
~Q(version_id=None))

I have tried a raw query and also a version of the query that uses 
exclude(), but that still returns None for date.

I am accessing the entries in the queryset through a for loop and simply 
accessing date through entry.date inside the for loop.

I am using Django version 1.6.5. I have also tried getting the values 
through the Django shell, to no success.

Any ideas on what could be wrong? I have tried a multitude of queries, none 
of them change the returned value of date. I have tried resyncing the DB. 
I've looked over the models and everything seems to be correct. Everything 
except the date works fine.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80ebbbe9-3a81-4feb-8d48-a9ccad8b1bd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to create a custom admin panel for many models

2014-07-04 Thread 9devmail
 

I want to create a custom ModelAdmin, but for a mix of models, not just one.

I have two example models:

class Article(models.Model):
author = models.GenericIPAddressField()
# ...
class Comment(models.Model):
author = models.GenericIPAddressField()
# ...

Now I want to be able to have a ModelAdmin with fields:

author
number_of_comments
number_of_articles

How can I achieve it?

I created a new ModelAdmin with overridden queryset method, but I was not 
able to register it, because Article and Comment are already registered.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a2d344f-755d-4108-83bd-2c672cce4e30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch error: Reverse for 'lebay_view_user_profile' with arguments '('',)' and keyword arguments '{}' not found.

2014-07-04 Thread Niccolò Lancellotti
Hi guys, i'm new in this group. I'm trying to upgrade a django project i 
found on internet, called 'little ebay', from django 1.2 to 1.5. It is a 
very simple project, there are only few files.
i'm going to append them... please help me, i'm going ma with that.

i'm appending only two of the various templates, the two templates involved 
in the error

Thank you all.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3104a0c9-e35b-48c3-b9d0-433f28c2a481%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{% extends "base.html" %}

{% load uni_form_tags %}

{% block title %}View User{% endblock %}

{% block content %}
{% ifequal user request.user.user %}
This is you!
{% endifequal %}
{{ user.first_name }} {{ user.last_name }}
{% ifequal user request.user.user %}
Edit Profile
{% endifequal %} 
Email: {{ user.email }}
Address Line 1: {{ user.address_line_1 }}
{% if user.address_line_2 %}
Address Line 2: {{ user.address_line_2 }}
{% endif %}
City: {{ user.city }}
State: {{ user.state }}
Zip: {{ user.zipcode }}
Phone: {{ user.phone }}
{% endblock %}
import datetime
from decimal import Decimal

from django import forms
from django.conf import settings
from django.contrib.auth import authenticate
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.forms.util import ValidationError
from django.contrib.admin import widgets as adminwidgets
from django.contrib.localflavor.us.forms import USPhoneNumberField, USZipCodeField

from lebay.apps.lebay.models import User, Seller, Item, AuctionEvent, Bid, Sales
from lebay.apps.lebay.constants import AUCTION_ITEM_STATUS_RUNNING

class UserLoginForm(forms.Form):
username = forms.CharField(label=u'User Name')
password = forms.CharField(label=u'Password', widget=forms.PasswordInput(render_value=False))

def clean(self):
cleaned_data = self.cleaned_data
username = cleaned_data.get('username', '')
password = cleaned_data.get('password', '')
user = authenticate(username=username, password=password)
if user is not None:
if not user.is_active:
raise ValidationError('This account is disable. Please constact the webmaster.') 
else:
raise ValidationError('Wrong username and or password. Try again.') 

return cleaned_data

def get_user(self):
username = self.cleaned_data.get('username', '')
password = self.cleaned_data.get('password', '')
user = authenticate(username=username, password=password)

return user

class AuctionSearchForm(forms.Form):
query = forms.CharField(max_length=200, required=False, label='')

def search(self):
cleaned_data = self.cleaned_data
cleaned_query = cleaned_data.get('query', '') 
if cleaned_query:
matching_auctions = AuctionEvent.objects.get_current_auctions().filter(Q(item__title__icontains=cleaned_query) | Q(item__description__icontains=cleaned_query))
else:
matching_auctions = AuctionEvent.objects.get_current_auctions()

return matching_auctions

class UserRegistrationForm(forms.ModelForm):
password = forms.CharField(label=u'Password', widget=forms.PasswordInput(render_value=False))
retyped_password = forms.CharField(label=u'Retype Password', widget=forms.PasswordInput(render_value=False))
zipcode = USZipCodeField()
phone = USPhoneNumberField()

def __init__(self, *args, **kwargs):
super(forms.ModelForm, self).__init__(*args, **kwargs)
self.fields.keyOrder = [
'username',
'first_name',
'last_name',
'email',
'password',
'retyped_password',
'address_line_1',
'address_line_2',
'city',
'state',
'zipcode',
'phone']

class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password', 'address_line_1', 'address_line_2', 'city', 'state', 'zipcode', 'phone']

def clean(self):
cleaned_data = self.cleaned_data
password = cleaned_data.get('password', '')
retyped_password = cleaned_data.get('retyped_password', '')

if password != retyped_password:
raise ValidationError('Password and retyped password didn\'t match.')

return cleaned_data

def save(self, force_insert=False, force_update=False, commit=True, 

Re: DateTimeField always returns None

2014-07-04 Thread trustedbox
Are you sure you're using the same DB ?
Test it by adding new record and instantly retrieve it.

пятница, 4 июля 2014 г., 12:01:15 UTC+3 пользователь William Granli написал:
>
> I am trying to create a queryset for getting the values of a DateTimeField 
> which is DATETIME in the DB.
>
> The class in models.py:
>
> class ChangeMetrics(models.Model):
> id = models.IntegerField(primary_key=True)
> file_id = models.ForeignKey(File, db_column = 'file_id')
> version_id = models.ForeignKey(Version, db_column = 'version_id')
> function_id = models.ForeignKey(Function, blank=True, db_column = 
> 'function_id')
> date = models.DateTimeField(blank=True, null=True)
> user = models.TextField(blank=True)
> changed = models.IntegerField(blank=True, null=True)
>
> The field in the SQL DB:
>
> date DATETIME
>
> The tuples are populated in the database and running SQL queries directly 
> on the DB is working perfectly.
>
> This is the queryset I am currently using in Django:
>
> queryset = ChangeMetrics.objects.filter(~Q(changed=None), ~Q(date=None), 
> ~Q(version_id=None))
>
> I have tried a raw query and also a version of the query that uses 
> exclude(), but that still returns None for date.
>
> I am accessing the entries in the queryset through a for loop and simply 
> accessing date through entry.date inside the for loop.
>
> I am using Django version 1.6.5. I have also tried getting the values 
> through the Django shell, to no success.
>
> Any ideas on what could be wrong? I have tried a multitude of queries, 
> none of them change the returned value of date. I have tried resyncing the 
> DB. I've looked over the models and everything seems to be correct. 
> Everything except the date works fine.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88be737b-03fb-478b-8ed5-37d0171bf35a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DateTimeField always returns None

2014-07-04 Thread Tom Evans
On Fri, Jul 4, 2014 at 10:01 AM, William Granli
 wrote:
> I am trying to create a queryset for getting the values of a DateTimeField
> which is DATETIME in the DB.
>
> The class in models.py:
>
> class ChangeMetrics(models.Model):
> id = models.IntegerField(primary_key=True)
> file_id = models.ForeignKey(File, db_column = 'file_id')
> version_id = models.ForeignKey(Version, db_column = 'version_id')
> function_id = models.ForeignKey(Function, blank=True, db_column =
> 'function_id')
> date = models.DateTimeField(blank=True, null=True)
> user = models.TextField(blank=True)
> changed = models.IntegerField(blank=True, null=True)
>
> The field in the SQL DB:
>
> date DATETIME
>
> The tuples are populated in the database and running SQL queries directly on
> the DB is working perfectly.
>
> This is the queryset I am currently using in Django:
>
> queryset = ChangeMetrics.objects.filter(~Q(changed=None), ~Q(date=None),
> ~Q(version_id=None))

Have you tried Q(date__isnull=False)?

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2BJgs5qdRJ4ECtWzcg_R%2BhVkxvv%3DM%3Dv%2BC2iUMgw_%3DWf-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: "ResourceWarning: unclosed" error using mysql-connector-python

2014-07-04 Thread Zemian Deng
No problem. Thanks for the reply.


On Fri, Jul 4, 2014 at 12:51 AM, cercatrova2  wrote:

>  On 04/07/14 05:09, Zemian Deng wrote:
>
> Hum... I am surprised that no one has experienced this warning msg yet, or
> maybe I can't catch anyone to reply.
>
>  For those are curious, I do now see mysql-connector-python 1.2.2 is
> available, and upgrading to this version got rid off these warnings.
>
> On Thursday, June 12, 2014 11:24:40 PM UTC-4, Zemian Deng wrote:
>>
>> Anyone?
>>
>> On Tuesday, June 10, 2014 11:26:18 PM UTC-4, Zemian Deng wrote:
>>>
>>> Hi there,
>>>
>>>  I am using mysql-connector-python (1.1.6) with Django (1.6.5) and
>>> myapp is working fine. But each SQL call to DB will result the following
>>> warning messages:
>>>
>>>   Exception ignored in: >> family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=6,
>>> laddr=('127.0.0.1', 62622), raddr=('127.0.0.1', 3306)>
>>>
>>> ResourceWarning: unclosed >> family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=6,
>>> laddr=('127.0.0.1', 62622), raddr=('127.0.0.1', 3306)>
>>>
>>>
>>>  Has anyone seen this and know a way to resolve it?
>>>  Also, FYI, I am using the following in my settings file.
>>> DATABASES = {
>>>  'default': {
>>>'ENGINE': 'mysql.connector.django',
>>>'NAME': 'mydb',
>>>'USER': 'test',
>>>'PASSWORD': 'test',
>>> },
>>> }
>>>
>>>  Thanks,
>>> Zemian
>>>
>>   --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a443d950-fe72-4380-bf61-1fc9c71c9af9%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> Zemian - I saw these warning messages too with 1.1.6 but indeed they went
> away with 1.2.2 about a month ago so I didn't post anything. Sorry but I
> didn't know of your message at the time.
>
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/53B632EE.2080203%40gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK3t1y38NhS1GH3XVR9aB2TcuzO5JLFXRad1Hct5sP_En822_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Mysql connections after started django app

2014-07-04 Thread Zemian Deng
@cercatrova2,

Yes, my original problem also was (and still is) with "MySQL Connection not
available" after the 8 hours timeout inactivity on webfaction hosting. I
have to restart it whenever this happens and then problem will go away. My
current workaround is to schedule a dummy crontab to hit my site every hour
to keep connection timeout refresh. Not ideal, but better than nothing so
far. Thus I am looking for some help here.

I really like MySQL, and I have tested my app with it already. It would be
a bummer to switch because of this just now. I have tried direct usage of
mysql.connection with just open and close a connection, and I do see the
process go away properly. This plus the number of process list is
increasing when I try simple "mysite" app lead me to think it might be
django related. I am not sure. Further testing would be need to verify
which end is causing the problem.

But good to hear PostgreSQL doesn't have the same issue though.



On Fri, Jul 4, 2014 at 1:06 AM, cercatrova2  wrote:

>  On 04/07/14 05:04, Zemian Deng wrote:
>
> Hi,
>
>  In my django settings.py I have set CONN_MAX_AGE=0 to use with MySQL DB,
> which I understood as closing conn after each request. However when I start
> a simple "mysite" tutorial with "python manage.py runserver", I see
> immediately 3 connections in mysql that will not close but in Sleep mode.
> Did I miss something here? How do we ensure these connections will get
> closed while the app is running?
>
>  mysql> show full processlist;
>
>
> +-+--+-+--+-+--+---+---+
>
> | Id  | User | Host| db   | Command | Time | State | Info
> |
>
>
> +-+--+-+--+-+--+---+---+
>
> | 316 | root | localhost   | NULL | Query   |0 | init  | show full
> processlist |
>
> | 317 | root | localhost:61695 | test | Sleep   |3 |   | NULL
> |
>
> | 318 | root | localhost:61696 | test | Sleep   |3 |   | NULL
> |
>
> | 319 | root | localhost:61697 | test | Sleep   |3 |   | NULL
> |
>
>
> +-+--+-+--+-+--+---+---+
>
> 4 rows in set (0.00 sec)
>
>
>  Thanks
>
> Zemian
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/33fcf156-42bd-4c07-819f-952a6b214b76%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> Zemian - I've run into this also (I think), but the problem showed up in a
> different way. First, after the mysql connection timeout expired, django
> would throw a "MySQL Connection not available" exception when trying to
> access the server. Second, it would throw the same exception when trying to
> access the server after the server had been restarted. This was all with
> CONN_MAX_AGE=0 which as you say should make django open and close a
> connection on each request.
>
> I didn't have time to research things further, but it seems to me that the
> issue is with mysql.connector.django i.e. mysql connector/python - it is
> somehow keeping its connection open client-side and when that connection
> goes away server-side then it gives up. I tried to bring the problem to the
> attention of the developer on his blog but he didn't respond. I guess a bug
> report should be posted instead.
>
> Anyway, these problems, coupled with some unsolvable timezone issues when
> trying to use mezzanine django cms with mysql connector/python, forced me
> to switch to postgresql, which is working very well so far.
>
> Good luck.
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/53B6363A.8090601%40gmail.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 receivi

Re: Mysql connections after started django app

2014-07-04 Thread cercatrova2

  
  
On 04/07/14 16:11, Zemian Deng wrote:


  @cercatrova2,

  
Yes,
my original problem also was
(and still is) with "MySQL
Connection not available" after the 8 hours timeout
inactivity on webfaction hosting. I have to restart it
whenever this happens and then problem will go away. My
current workaround is to schedule a dummy crontab to hit my
site every hour to keep connection timeout refresh. Not
ideal, but better than nothing so far. Thus I am looking for
some help here.

  
I
really like MySQL, and I have tested my app with it already.
It would be a bummer to switch because of this just now. I
have tried direct usage of mysql.connection with just open
and close a connection, and I do see the process go away
properly. This plus the number of process list is increasing
when I try simple "mysite" app lead me to think it might be
django related. I am not sure. Further testing would be need
to verify which end is causing the problem.

  
But
good to hear PostgreSQL doesn't have the same issue though.

  
  
  

On Fri, Jul 4, 2014 at 1:06 AM,
  cercatrova2 
  wrote:
  

  

  On 04/07/14 05:04, Zemian Deng wrote:
  
  
Hi,
  
  
  In my django settings.py I have set
CONN_MAX_AGE=0 to use with MySQL DB, which I
understood as closing conn after each request.
However when I start a simple "mysite" tutorial
with "python manage.py runserver", I see
immediately 3 connections in mysql that will not
close but in Sleep mode. Did I miss something
here? How do we ensure these connections will
get closed while the app is running?
  
  
  
mysql> show full processlist;
+-+--+-+--+-+--+---+---+
| Id  | User | Host            | db   |
  Command | Time | State | Info                 
  |
+-+--+-+--+-+--+---+---+
| 316 | root | localhost       | NULL | Query
    |    0 | init  | show full processlist |
| 317 | root | localhost:61695 | test | Sleep
    |    3 |       | NULL                  |
| 318 | root | localhost:61696 | test | Sleep
    |    3 |       | NULL                  |
| 319 | root | localhost:61697 | test | Sleep
    |    3 |       | NULL                  |
+-+--+-+--+-+--+---+---+
4 rows in set (0.00 sec)


Thanks
Zemian
  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/33fcf156-42bd-4c07-819f-952a6b214b76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  
  

  
  Zemian - I've run into this also (I think), but the
  problem showed up in a different way. First, after the
  mysql connection timeout expired, django would throw a
  "MySQL Connection not available" exception when trying to
  access the server. Second, it would throw the same
  exception when trying to access the server after the
  server had been restarted. This was all with
  CONN_MAX_AGE=0 wh

Simple History - Field Change

2014-07-04 Thread Aaron Reabow
Hi all,

I am getting this error on a modelform

smallint out of range



But the form is actually submitting just fine and being stored in the DB.  I 
used to have a positive small int, but have changed it  (dropped the offending 
table, resync'ed, restarted the server...)

I have history = HistoricalRecords() as one of the fields  (ie am tracking 
changes with django-simple-history), and I wonder if this is effecting my 
ability to make changes to the model.


My other thought is that it is a caching problem somewhere.


has anyone come across this problem and have any idea how to fix?


many thanks,


Aaron

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6af23e8d-9f15-477d-843f-dc9c33b7edf9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Mysql connections after started django app

2014-07-04 Thread François Schiettecatte
Hi

I have a little experience with this, and I have posted about this here before.

The "MySQL Connection not available" message will occur when MySQL is dropping 
the connection before Django is done with it, ie Django is trying to send 
something down a dead connection.

I would look at CONN_MAX_AGE in DATABASES (in settings.py) and wait_timeout in 
my.cnf, the first should be lower than the second.

For example I have these settings for a number of projects:

   'CONN_MAX_AGE': 3500,   # 3500 seconds because 
wait_timeout = 3600 in my.cnf

And this for another:

'CONN_MAX_AGE': 50, # 50 seconds because 
wait_timeout = 60 in my.cnf

Not setting CONN_MAX_AGE (or setting it to 0) in 1.6 caused the "MySQL 
Connection not available" issue, I suspect there is a bug in how Django handles 
its pooling but I have not checked. Seeing Sleeping connections on MySQL is 
suggestive of that. A Sleeping connection just means it is idle and waiting for 
stuff.

I have a number of long running scripts, where more than an hour (3600 seconds) 
can elapse between database accesses, and I find I have to ping the connections 
to see if they are still alive before I do any database accesses, so I call the 
following method to ping the connections, and close off dead connections:


from django.db import connection

def checkConnection():

# Check the connection, close if needed
try:
connection.connection.ping()
# print 'INFO: connection.connection.ping()'
except:
connection.close()
# print 'INFO: connection.close()'

 
Hope this helps.

https://docs.djangoproject.com/en/1.6/ref/databases/
https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-CONN_MAX_AGE

Cheers

François


On Jul 4, 2014, at 10:46 AM, cercatrova2  wrote:

> On 04/07/14 16:11, Zemian Deng wrote:
>> @cercatrova2,
>> 
>> Yes, my original problem also was (and still is) with "MySQL Connection not 
>> available" after the 8 hours timeout inactivity on webfaction hosting. I 
>> have to restart it whenever this happens and then problem will go away. My 
>> current workaround is to schedule a dummy crontab to hit my site every hour 
>> to keep connection timeout refresh. Not ideal, but better than nothing so 
>> far. Thus I am looking for some help here.
>> 
>> I really like MySQL, and I have tested my app with it already. It would be a 
>> bummer to switch because of this just now. I have tried direct usage of 
>> mysql.connection with just open and close a connection, and I do see the 
>> process go away properly. This plus the number of process list is increasing 
>> when I try simple "mysite" app lead me to think it might be django related. 
>> I am not sure. Further testing would be need to verify which end is causing 
>> the problem.
>> 
>> But good to hear PostgreSQL doesn't have the same issue though.
>> 
>> 
>> 
>> On Fri, Jul 4, 2014 at 1:06 AM, cercatrova2  wrote:
>> On 04/07/14 05:04, Zemian Deng wrote:
>>> Hi,
>>> 
>>> In my django settings.py I have set CONN_MAX_AGE=0 to use with MySQL DB, 
>>> which I understood as closing conn after each request. However when I start 
>>> a simple "mysite" tutorial with "python manage.py runserver", I see 
>>> immediately 3 connections in mysql that will not close but in Sleep mode. 
>>> Did I miss something here? How do we ensure these connections will get 
>>> closed while the app is running?
>>> 
>>> mysql> show full processlist;
>>> 
>>> +-+--+-+--+-+--+---+---+
>>> 
>>> | Id  | User | Host| db   | Command | Time | State | Info   
>>>|
>>> 
>>> +-+--+-+--+-+--+---+---+
>>> 
>>> | 316 | root | localhost   | NULL | Query   |0 | init  | show full 
>>> processlist |
>>> 
>>> | 317 | root | localhost:61695 | test | Sleep   |3 |   | NULL   
>>>|
>>> 
>>> | 318 | root | localhost:61696 | test | Sleep   |3 |   | NULL   
>>>|
>>> 
>>> | 319 | root | localhost:61697 | test | Sleep   |3 |   | NULL   
>>>|
>>> 
>>> +-+--+-+--+-+--+---+---+
>>> 
>>> 4 rows in set (0.00 sec)
>>> 
>>> 
>>> Thanks
>>> 
>>> Zemian
>>> 
>>> -- 
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/33fcf156-42bd-4c07-819f-952a6b214b76%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>> 
>> Zemian - I'

Re: Simple History - Field Change

2014-07-04 Thread Cal Leeming [Simplicity Media Ltd]
Can you please paste the full clear text stacktrace?

Cal


On Fri, Jul 4, 2014 at 3:49 PM, Aaron Reabow  wrote:

> Hi all,
>
> I am getting this error on a modelform
>
> smallint out of range
>
>
>
> But the form is actually submitting just fine and being stored in the DB.  I 
> used to have a positive small int, but have changed it  (dropped the 
> offending table, resync'ed, restarted the server...)
>
> I have history = HistoricalRecords() as one of the fields  (ie am tracking 
> changes with django-simple-history), and I wonder if this is effecting my 
> ability to make changes to the model.
>
>
> My other thought is that it is a caching problem somewhere.
>
>
> has anyone come across this problem and have any idea how to fix?
>
>
> many thanks,
>
>
> Aaron
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6af23e8d-9f15-477d-843f-dc9c33b7edf9%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHKQagHn-Bwrg_nHyqO6fd63W4S5L34-Zhe4yz%3Dox9nKtfCsWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple History - Field Change

2014-07-04 Thread Aaron Reabow
Environment:


Request Method: POST
Request URL: upon request :)

Django Version: 1.6.2
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.sites',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'myproject.ngc',
 'registration',
 'crispy_forms',
 'floppyforms',
 'simple_history')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/core/handlers/base.py" 
in get_response
  114. response = wrapped_callback(request, 
*callback_args, **callback_kwargs)
File "/home/metadata/webapps/greenhouse/myproject/myproject/ngc/views.py" 
in leadManagementView
  540. model_instance.save()
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in save
  545.force_update=force_update, 
update_fields=update_fields)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in save_base
  582.update_fields=update_fields, 
raw=raw, using=using)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/dispatch/dispatcher.py" 
in send
  185. response = receiver(signal=self, sender=sender, **named)
File 
"/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py" 
in post_save
  209. self.create_historical_record(instance, created and '+' 
or '~')
File 
"/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py" 
in create_historical_record
  222.history_user=history_user, **attrs)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py" 
in create
  157. return self.get_queryset().create(**kwargs)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py" 
in create
  319. obj.save(force_insert=True, using=self.db)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in save
  545.force_update=force_update, 
update_fields=update_fields)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in save_base
  573. updated = self._save_table(raw, cls, force_insert, 
force_update, using, update_fields)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in _save_table
  654. result = self._do_insert(cls._base_manager, using, 
fields, update_pk, raw)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
in _do_insert
  687.using=using, raw=raw)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py" 
in _insert
  232. return insert_query(self.model, objs, fields, **kwargs)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py" 
in insert_query
  1511. return query.get_compiler(using=using).execute_sql(return_id)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/sql/compiler.py"
 
in execute_sql
  899. cursor.execute(sql, params)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/backends/util.py" 
in execute
  69. return super(CursorDebugWrapper, self).execute(sql, 
params)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/backends/util.py" 
in execute
  53. return self.cursor.execute(sql, params)
File "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/utils.py" 
in __exit__
  99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File 
"/home/metadata/webapps/greenhouse/lib/python2.7/django/db/backends/util.py" 
in execute
  53. return self.cursor.execute(sql, params)

Exception Type: DataError at /leads
Exception Value: smallint out of range


On Friday, 4 July 2014 17:43:50 UTC+2, Cal Leeming [Simplicity Media Ltd] 
wrote:
>
> Can you please paste the full clear text stacktrace?
>
> Cal
>
>
> On Fri, Jul 4, 2014 at 3:49 PM, Aaron Reabow  > wrote:
>
>> Hi all,
>>
>> I am getting this error on a modelform
>>
>> smallint out of range
>>
>>
>>
>> But the form is actually submitting just fine and being stored in the DB.  I 
>> used to have a positive small int, but have changed it  (dropped the 
>> offending table, resync'ed, restarted the server...)
>>
>> I have history = HistoricalRecords() as one of the fields  (ie am tracking 
>> changes with django-simple-history), and I wonder if this is effecting my 
>> ability to make changes to the mod

Unit testing - return HttpResponseRedirect('/accounts/loggedin')

2014-07-04 Thread Pepsodent Cola
Hi coverage has highlighted that I have no unit test for the line, 
regarding *HttpResponseRedirect('/accounts/loggedin')*.
How can I write a test that makes Coverage happy regarding this?


views.py

def auth_view(request): 
username = request.POST.get('username', '') 
password = request.POST.get('password', '') 
user = auth.authenticate(username=username, password=password) 

if user is not None: 
auth.login(request, user)   
return HttpResponseRedirect('*/accounts/loggedin*')   
else:
return HttpResponseRedirect('/accounts/invalid') 
#___

def loggedin(request):
return render_to_response('loggedin.html',
   {'full_name': 
request.user.username})
#___

def invalid_login(request):
return render_to_response('invalid_login.html')
#___




url.py

# user auth urls
url(r'^accounts/login/$', 'navi.views.login'),
url(r'^accounts/auth/$', 'navi.views.*auth_view*'),
url(r'^accounts/logout/$', 'navi.views.logout'),
url(r'^accounts/loggedin/$', 'navi.views.loggedin'),
url(r'^accounts/invalid/$', 'navi.views.invalid_login'),



test.py

###
#Forms
###

class FormTest(TestCase):
# Create User
def setUp(self):
self.user = User.objects.create_user(username='captain', 
password='america')

# Logged in
def test_Logged_in(self):
self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')
self.assertEqual(login, True)

resp = self.client.get('/accounts/profile/')
#  resp = self.client.get(reverse('userprofile:user_profile'))
self.assertEqual(resp.status_code, 200)

#  resp = self.client.post('/accounts/profile/', {'username':'captain', 
'password':'america'}, follow=True)
resp = self.client.post('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)

resp = self.client.get('/accounts/fakepage/')
resp = self.client.get('/accounts/loggedin/')


# Invalid login
def test_Invalid_login(self):
resp = self.client.get('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)
self.assertRedirects(resp, 
'/accounts/login/?next=/accounts/profile/')

self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')
self.assertEqual(login, True)
resp = self.client.get(reverse('userprofile:user_profile'), 
follow=True)
self.assertEqual(resp.status_code, 200)

#  resp = self.client.post('/accounts/profile/', {'username':'captain', 
'password':'america'}, follow=True)
resp = self.client.post('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)


class AuthTest(TestCase):
def test_auth_view(self):
resp = self.client.get('/accounts/auth/', follow=True)
self.assertEqual(resp.status_code, 200)
self.assertRedirects(resp, '/accounts/invalid/')

def test_loggedin(self):
resp = self.client.post('/accounts/loggedin/')
self.assertEqual(resp.status_code, 200)

def test_logout(self):
resp = self.client.get('/accounts/logout/')
self.assertEqual(resp.status_code, 200)
#___



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3528b26d-52f9-4e26-aaab-631e955936e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple History - Field Change

2014-07-04 Thread Cal Leeming [Simplicity Media Ltd]
It sounds like you haven't applied the table changes to the cloned table
which it creates to track changes.

I'd advice using something like South to manage your schema changes, and
this should work out of the box with django-simple-history.

For now, you can delete the cloned table and re-sync, you will naturally
lose the historical data but if you deleted the original then this probably
won't matter.

It's also worth mentioning that the design approach
of django-simple-history is completely wrong, and personally I wouldn't
recommend using it. Feel free to start a separate thread if you'd like to
discuss that further though as it's slightly off topic for this thread.

Let us know how you get on.

Cal


On Fri, Jul 4, 2014 at 4:47 PM, Aaron Reabow  wrote:

> Environment:
>
>
> Request Method: POST
> Request URL: upon request :)
>
> Django Version: 1.6.2
> Python Version: 2.7.5
> Installed Applications:
> ('django.contrib.admin',
>  'django.contrib.admindocs',
>  'django.contrib.auth',
>  'django.contrib.sites',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'myproject.ngc',
>  'registration',
>  'crispy_forms',
>  'floppyforms',
>  'simple_history')
> Installed Middleware:
> ('django.contrib.sessions.middleware.SessionMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
>  'django.middleware.clickjacking.XFrameOptionsMiddleware')
>
>
> Traceback:
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/core/handlers/base.py"
> in get_response
>   114. response = wrapped_callback(request,
> *callback_args, **callback_kwargs)
> File "/home/metadata/webapps/greenhouse/myproject/myproject/ngc/views.py"
> in leadManagementView
>   540. model_instance.save()
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in save
>   545.force_update=force_update,
> update_fields=update_fields)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in save_base
>   582.update_fields=update_fields,
> raw=raw, using=using)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/dispatch/dispatcher.py"
> in send
>   185. response = receiver(signal=self, sender=sender, **named)
> File
> "/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py"
> in post_save
>   209. self.create_historical_record(instance, created and '+'
> or '~')
> File
> "/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py"
> in create_historical_record
>   222.history_user=history_user, **attrs)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py"
> in create
>   157. return self.get_queryset().create(**kwargs)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py"
> in create
>   319. obj.save(force_insert=True, using=self.db)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in save
>   545.force_update=force_update,
> update_fields=update_fields)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in save_base
>   573. updated = self._save_table(raw, cls, force_insert,
> force_update, using, update_fields)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in _save_table
>   654. result = self._do_insert(cls._base_manager, using,
> fields, update_pk, raw)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py"
> in _do_insert
>   687.using=using, raw=raw)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py"
> in _insert
>   232. return insert_query(self.model, objs, fields, **kwargs)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py"
> in insert_query
>   1511. return query.get_compiler(using=using).execute_sql(return_id)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/sql/compiler.py"
> in execute_sql
>   899. cursor.execute(sql, params)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/backends/util.py"
> in execute
>   69. return super(CursorDebugWrapper, self).execute(sql,
> params)
> File
> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/backends/util.py"
> in execute
>   53. return self.cursor.execute(sql, params)
> File "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/utils.py"
> in __exit__
>   99. six.reraise(dj_exc_type, dj_exc_value, traceback)

Re: Mysql connections after started django app

2014-07-04 Thread Zemian Deng
@cercatrova2, yes, these problems are coming using python3 and the
mysql-connector-python and I am using their "mysql.connector.django".

Currenly I have briefly experimented the default django.db.backends.mysql
with Python3 driver https://github.com/clelland/MySQL-for-Python-3, but I
still see the Sleep connections in the "mysite" project. So I am not too
sure what's going on yet. Would have to dig little deeper in code to find
out. I have already committed some effort into my app including testing
with python3, so I am not ready to switch back into python 2.7 yet.




On Fri, Jul 4, 2014 at 10:46 AM, cercatrova2  wrote:

>  On 04/07/14 16:11, Zemian Deng wrote:
>
> @cercatrova2,
>
>  Yes, my original problem also was (and still is) with "MySQL Connection
> not available" after the 8 hours timeout inactivity on webfaction hosting.
> I have to restart it whenever this happens and then problem will go away.
> My current workaround is to schedule a dummy crontab to hit my site every
> hour to keep connection timeout refresh. Not ideal, but better than nothing
> so far. Thus I am looking for some help here.
>
>  I really like MySQL, and I have tested my app with it already. It would
> be a bummer to switch because of this just now. I have tried direct usage
> of mysql.connection with just open and close a connection, and I do see the
> process go away properly. This plus the number of process list is
> increasing when I try simple "mysite" app lead me to think it might be
> django related. I am not sure. Further testing would be need to verify
> which end is causing the problem.
>
>  But good to hear PostgreSQL doesn't have the same issue though.
>
>
>
> On Fri, Jul 4, 2014 at 1:06 AM, cercatrova2  wrote:
>
>>   On 04/07/14 05:04, Zemian Deng wrote:
>>
>> Hi,
>>
>>  In my django settings.py I have set CONN_MAX_AGE=0 to use with MySQL
>> DB, which I understood as closing conn after each request. However when I
>> start a simple "mysite" tutorial with "python manage.py runserver", I see
>> immediately 3 connections in mysql that will not close but in Sleep mode.
>> Did I miss something here? How do we ensure these connections will get
>> closed while the app is running?
>>
>>  mysql> show full processlist;
>>
>>
>> +-+--+-+--+-+--+---+---+
>>
>> | Id  | User | Host| db   | Command | Time | State | Info
>>   |
>>
>>
>> +-+--+-+--+-+--+---+---+
>>
>> | 316 | root | localhost   | NULL | Query   |0 | init  | show
>> full processlist |
>>
>> | 317 | root | localhost:61695 | test | Sleep   |3 |   | NULL
>>   |
>>
>> | 318 | root | localhost:61696 | test | Sleep   |3 |   | NULL
>>   |
>>
>> | 319 | root | localhost:61697 | test | Sleep   |3 |   | NULL
>>   |
>>
>>
>> +-+--+-+--+-+--+---+---+
>>
>> 4 rows in set (0.00 sec)
>>
>>
>>  Thanks
>>
>> Zemian
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/33fcf156-42bd-4c07-819f-952a6b214b76%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>  Zemian - I've run into this also (I think), but the problem showed up
>> in a different way. First, after the mysql connection timeout expired,
>> django would throw a "MySQL Connection not available" exception when trying
>> to access the server. Second, it would throw the same exception when trying
>> to access the server after the server had been restarted. This was all with
>> CONN_MAX_AGE=0 which as you say should make django open and close a
>> connection on each request.
>>
>> I didn't have time to research things further, but it seems to me that
>> the issue is with mysql.connector.django i.e. mysql connector/python - it
>> is somehow keeping its connection open client-side and when that connection
>> goes away server-side then it gives up. I tried to bring the problem to the
>> attention of the developer on his blog but he didn't respond. I guess a bug
>> report should be posted instead.
>>
>> Anyway, these problems, coupled with some unsolvable timezone issues when
>> trying to use mezzanine django cms with mysql connector/python, forced me
>> to switch to postgresql, which is working very well so far.
>>
>> Good luck.
>>
>>  --
>> You received t

Re: Mysql connections after started django app

2014-07-04 Thread Zemian Deng
Thanks for the tips @Francois! Yeah, I already have this CONN_MAX_AGE set
to 0. I even try some positive number, but there is still Sleep connections
remain after the app is started and running without any traffic. Which is
not what I expect when set to 0 value.

I don't even have fancy background tasks that need long running connection
time. But my site is only been use every few days per week, so it has
timeout issue when first use. As I mentioned, my current workaround is have
a crontab task to "curl" my site hourly to keep it alive. Even at this is
not completely reliable since there are 5 established connections, and not
always refresh all of them per ping.



On Fri, Jul 4, 2014 at 11:24 AM, François Schiettecatte <
fschietteca...@gmail.com> wrote:

> Hi
>
> I have a little experience with this, and I have posted about this here
> before.
>
> The "MySQL Connection not available" message will occur when MySQL is
> dropping the connection before Django is done with it, ie Django is trying
> to send something down a dead connection.
>
> I would look at CONN_MAX_AGE in DATABASES (in settings.py) and
> wait_timeout in my.cnf, the first should be lower than the second.
>
> For example I have these settings for a number of projects:
>
>'CONN_MAX_AGE': 3500,   # 3500 seconds because
> wait_timeout = 3600 in my.cnf
>
> And this for another:
>
> 'CONN_MAX_AGE': 50, # 50 seconds because
> wait_timeout = 60 in my.cnf
>
> Not setting CONN_MAX_AGE (or setting it to 0) in 1.6 caused the "MySQL
> Connection not available" issue, I suspect there is a bug in how Django
> handles its pooling but I have not checked. Seeing Sleeping connections on
> MySQL is suggestive of that. A Sleeping connection just means it is idle
> and waiting for stuff.
>
> I have a number of long running scripts, where more than an hour (3600
> seconds) can elapse between database accesses, and I find I have to ping
> the connections to see if they are still alive before I do any database
> accesses, so I call the following method to ping the connections, and close
> off dead connections:
>
>
> from django.db import connection
>
> def checkConnection():
>
> # Check the connection, close if needed
> try:
> connection.connection.ping()
> # print 'INFO: connection.connection.ping()'
> except:
> connection.close()
> # print 'INFO: connection.close()'
>
>
> Hope this helps.
>
> https://docs.djangoproject.com/en/1.6/ref/databases/
>
> https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-CONN_MAX_AGE
>
> Cheers
>
> François
>
>
> On Jul 4, 2014, at 10:46 AM, cercatrova2  wrote:
>
> > On 04/07/14 16:11, Zemian Deng wrote:
> >> @cercatrova2,
> >>
> >> Yes, my original problem also was (and still is) with "MySQL Connection
> not available" after the 8 hours timeout inactivity on webfaction hosting.
> I have to restart it whenever this happens and then problem will go away.
> My current workaround is to schedule a dummy crontab to hit my site every
> hour to keep connection timeout refresh. Not ideal, but better than nothing
> so far. Thus I am looking for some help here.
> >>
> >> I really like MySQL, and I have tested my app with it already. It would
> be a bummer to switch because of this just now. I have tried direct usage
> of mysql.connection with just open and close a connection, and I do see the
> process go away properly. This plus the number of process list is
> increasing when I try simple "mysite" app lead me to think it might be
> django related. I am not sure. Further testing would be need to verify
> which end is causing the problem.
> >>
> >> But good to hear PostgreSQL doesn't have the same issue though.
> >>
> >>
> >>
> >> On Fri, Jul 4, 2014 at 1:06 AM, cercatrova2 
> wrote:
> >> On 04/07/14 05:04, Zemian Deng wrote:
> >>> Hi,
> >>>
> >>> In my django settings.py I have set CONN_MAX_AGE=0 to use with MySQL
> DB, which I understood as closing conn after each request. However when I
> start a simple "mysite" tutorial with "python manage.py runserver", I see
> immediately 3 connections in mysql that will not close but in Sleep mode.
> Did I miss something here? How do we ensure these connections will get
> closed while the app is running?
> >>>
> >>> mysql> show full processlist;
> >>>
> >>>
> +-+--+-+--+-+--+---+---+
> >>>
> >>> | Id  | User | Host| db   | Command | Time | State | Info
>  |
> >>>
> >>>
> +-+--+-+--+-+--+---+---+
> >>>
> >>> | 316 | root | localhost   | NULL | Query   |0 | init  | show
> full processlist |
> >>>
> >>> | 317 | root | localhost:61695 | test | Sleep   |3 |   | NULL
>  |
> >>>
> >>> | 318 | root | localhost:61696 | test | Sleep   |3 |   | NULL
>  |
> >>>
> >>> | 319 | root | localhost:61697 | 

Re: Mysql connections after started django app

2014-07-04 Thread François Schiettecatte
Hi

Again I think there is a bug somewhere in how django handles CONN_MAX_AGE when 
it is not set or set to 0, you should not be seeing those sleeping connections. 

It is perfectly fine to set CONN_MAX_AGE to some number, though keep it to less 
than the wait_timeout in my.cnf. You will still see sleeping connections but 
that is normal with a connection pool. Django will create a number of 
connections to the database as needed, reusing then when appropriate and 
closing them after the timeout you set. This will save you from having to ping 
your site to maintain the connections. Setting up a connection to MySQL is very 
fast so there should be performance issues if you set CONN_MAX_AGE to something 
like 60 (again check my.cnf).

Cheers

François


On Jul 4, 2014, at 12:39 PM, Zemian Deng  wrote:

> Thanks for the tips @Francois! Yeah, I already have this CONN_MAX_AGE set to 
> 0. I even try some positive number, but there is still Sleep connections 
> remain after the app is started and running without any traffic. Which is not 
> what I expect when set to 0 value.
> 
> I don't even have fancy background tasks that need long running connection 
> time. But my site is only been use every few days per week, so it has timeout 
> issue when first use. As I mentioned, my current workaround is have a crontab 
> task to "curl" my site hourly to keep it alive. Even at this is not 
> completely reliable since there are 5 established connections, and not always 
> refresh all of them per ping.
> 
> 
> 
> On Fri, Jul 4, 2014 at 11:24 AM, François Schiettecatte 
>  wrote:
> Hi
> 
> I have a little experience with this, and I have posted about this here 
> before.
> 
> The "MySQL Connection not available" message will occur when MySQL is 
> dropping the connection before Django is done with it, ie Django is trying to 
> send something down a dead connection.
> 
> I would look at CONN_MAX_AGE in DATABASES (in settings.py) and wait_timeout 
> in my.cnf, the first should be lower than the second.
> 
> For example I have these settings for a number of projects:
> 
>'CONN_MAX_AGE': 3500,   # 3500 seconds because 
> wait_timeout = 3600 in my.cnf
> 
> And this for another:
> 
> 'CONN_MAX_AGE': 50, # 50 seconds because 
> wait_timeout = 60 in my.cnf
> 
> Not setting CONN_MAX_AGE (or setting it to 0) in 1.6 caused the "MySQL 
> Connection not available" issue, I suspect there is a bug in how Django 
> handles its pooling but I have not checked. Seeing Sleeping connections on 
> MySQL is suggestive of that. A Sleeping connection just means it is idle and 
> waiting for stuff.
> 
> I have a number of long running scripts, where more than an hour (3600 
> seconds) can elapse between database accesses, and I find I have to ping the 
> connections to see if they are still alive before I do any database accesses, 
> so I call the following method to ping the connections, and close off dead 
> connections:
> 
> 
> from django.db import connection
> 
> def checkConnection():
> 
> # Check the connection, close if needed
> try:
> connection.connection.ping()
> # print 'INFO: connection.connection.ping()'
> except:
> connection.close()
> # print 'INFO: connection.close()'
> 
> 
> Hope this helps.
> 
> https://docs.djangoproject.com/en/1.6/ref/databases/
> https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-CONN_MAX_AGE
> 
> Cheers
> 
> François
> 
> 
> On Jul 4, 2014, at 10:46 AM, cercatrova2  wrote:
> 
> > On 04/07/14 16:11, Zemian Deng wrote:
> >> @cercatrova2,
> >>
> >> Yes, my original problem also was (and still is) with "MySQL Connection 
> >> not available" after the 8 hours timeout inactivity on webfaction hosting. 
> >> I have to restart it whenever this happens and then problem will go away. 
> >> My current workaround is to schedule a dummy crontab to hit my site every 
> >> hour to keep connection timeout refresh. Not ideal, but better than 
> >> nothing so far. Thus I am looking for some help here.
> >>
> >> I really like MySQL, and I have tested my app with it already. It would be 
> >> a bummer to switch because of this just now. I have tried direct usage of 
> >> mysql.connection with just open and close a connection, and I do see the 
> >> process go away properly. This plus the number of process list is 
> >> increasing when I try simple "mysite" app lead me to think it might be 
> >> django related. I am not sure. Further testing would be need to verify 
> >> which end is causing the problem.
> >>
> >> But good to hear PostgreSQL doesn't have the same issue though.
> >>
> >>
> >>
> >> On Fri, Jul 4, 2014 at 1:06 AM, cercatrova2  wrote:
> >> On 04/07/14 05:04, Zemian Deng wrote:
> >>> Hi,
> >>>
> >>> In my django settings.py I have set CONN_MAX_AGE=0 to use with MySQL DB, 
> >>> which I understood as closing conn after each request. However when I 
> >>> start a simple "mysite" tutorial with "python manage.

settings.configure() does not allow me to access custom variables in settings.py

2014-07-04 Thread Chen Xu
Hi Everyone,
I want to access some variables in my settings.py without starting my
server, I know I will have to run settings.configure(); however, running
settings.configure() does not allow me to access my custom variables.

What should I do with that.


Thanks

-- 
⚡ Chen Xu ⚡

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACac-qbCUJ3WCDVN022%3DU6nnh40X4tYPiW8oJ6q%3DY_LTGN9Bhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Cursor.Execute Issue with Postgresql

2014-07-04 Thread Jason Hawkins


I ran into a problem with cursor.execute, moved onto a completely separate 
part of my program, and ran into the same issue. I get that the value of a 
cursor return is: "django.db.backends.util.CursorDebugWrapper object". My 
code in my view is:

model_id.execute("SELECT id FROM \"{0}\".\"{1}\" where 
model_region='{2}'".format("public","pecasRunLog_modelinstance", model_name))

In another .py file I have:

run_id.execute("SELECT id FROM \"pecasRunLog_runinstance\" where 
run_name='{0}'".format(schema+timestamp))

In both cases, the code runs correctly in postgresql and I have similar 
code:

region_id.execute("SELECT id FROM \"pecasRunLog_modelinstance\" where 
model_region='{0}'".format(region))

which runs correctly.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db494ceb-7ec9-4929-ae60-3338f57a4f59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: settings.configure() does not allow me to access custom variables in settings.py

2014-07-04 Thread Mike Dewhirst

On 5/07/2014 7:12 AM, Chen Xu wrote:

Hi Everyone,
I want to access some variables in my settings.py without starting my
server, I know I will have to run settings.configure(); however, running
settings.configure() does not allow me to access my custom variables.

What should I do with that.


Perhaps read in the settings file and look for the settings of interest 
using plain python. Should not take too long and it would make a useful 
little utility. If necessary, hack settings.configure() to use your 
utility when it doesn't find a Django setting. Maybe submit the 
resulting improvement as a patch?


Mike




Thanks

--
âš¡ Chen Xu âš¡

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CACac-qbCUJ3WCDVN022%3DU6nnh40X4tYPiW8oJ6q%3DY_LTGN9Bhw%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53B748C2.1010306%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Journalists in the Django community, journalism advice

2014-07-04 Thread Elena Williams
Hey everybody,

&tldr; Looking for Journalists/former-Journalists/Journalism grads in the
community for any advice they might have.

I'm giving a talk at DjangoConAU more-or-less about communicating news in
community.

Django has a proud journalistic tradition and as such it seems remiss to
*not* at least ask around amongst the actual news-communications trained
people in the community for any advice or pointers they may have for this
presentation (I need all the help I can get).

I know our erstwhile-BDFLs were both journalism graduates, but:

 * Does anyone know of any other journalist/news types in our community I
should contact?

 * Anyone have any notable news/journalism advice I should be passing along?

Or, just contact me if you think there's anything I should mention, or have
any friendly advice, thank you!
---
Elena Williams :)
@elequ

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMRRKVd3GxcbgRLpzEhmwLQwD6f%3D_Mvt8hAiYbN1Gk91JCZTSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Journalists in the Django community, journalism advice

2014-07-04 Thread Cesar Mojarro
https://pypi.python.org/pypi/django-news


On Fri, Jul 4, 2014 at 9:43 PM, Elena Williams  wrote:

> Hey everybody,
>
> &tldr; Looking for Journalists/former-Journalists/Journalism grads in the
> community for any advice they might have.
>
> I'm giving a talk at DjangoConAU more-or-less about communicating news in
> community.
>
> Django has a proud journalistic tradition and as such it seems remiss to
> *not* at least ask around amongst the actual news-communications trained
> people in the community for any advice or pointers they may have for this
> presentation (I need all the help I can get).
>
> I know our erstwhile-BDFLs were both journalism graduates, but:
>
>  * Does anyone know of any other journalist/news types in our community I
> should contact?
>
>  * Anyone have any notable news/journalism advice I should be passing
> along?
>
> Or, just contact me if you think there's anything I should mention, or
> have any friendly advice, thank you!
> ---
> Elena Williams :)
> @elequ
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMRRKVd3GxcbgRLpzEhmwLQwD6f%3D_Mvt8hAiYbN1Gk91JCZTSg%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHXGZtorM7cJ%2BMeYDHgFjT%3DC7%2BTm%3DQd6ctcRV2NmkaLdd1%3DTEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Journalists in the Django community, journalism advice

2014-07-04 Thread Cesar Mojarro
https://github.com/Fantomas42/django-blog-zinnia


On Fri, Jul 4, 2014 at 10:11 PM, Cesar Mojarro  wrote:

> https://pypi.python.org/pypi/django-news
>
>
> On Fri, Jul 4, 2014 at 9:43 PM, Elena Williams  wrote:
>
>> Hey everybody,
>>
>> &tldr; Looking for Journalists/former-Journalists/Journalism grads in the
>> community for any advice they might have.
>>
>> I'm giving a talk at DjangoConAU more-or-less about communicating news in
>> community.
>>
>> Django has a proud journalistic tradition and as such it seems remiss to
>> *not* at least ask around amongst the actual news-communications trained
>> people in the community for any advice or pointers they may have for this
>> presentation (I need all the help I can get).
>>
>> I know our erstwhile-BDFLs were both journalism graduates, but:
>>
>>  * Does anyone know of any other journalist/news types in our community I
>> should contact?
>>
>>  * Anyone have any notable news/journalism advice I should be passing
>> along?
>>
>> Or, just contact me if you think there's anything I should mention, or
>> have any friendly advice, thank you!
>> ---
>> Elena Williams :)
>> @elequ
>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMRRKVd3GxcbgRLpzEhmwLQwD6f%3D_Mvt8hAiYbN1Gk91JCZTSg%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHXGZtqyDquaSTxnx2sZnM_oZu04zbKa1MF3yZ45UK1rqM1QJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Journalists in the Django community, journalism advice

2014-07-04 Thread Cesar Mojarro
http://devwiki.beloblotskiy.com/index.php5/Django_news_application_(avbnews)_-_part_1


On Fri, Jul 4, 2014 at 10:12 PM, Cesar Mojarro  wrote:

> https://github.com/Fantomas42/django-blog-zinnia
>
>
> On Fri, Jul 4, 2014 at 10:11 PM, Cesar Mojarro  wrote:
>
>> https://pypi.python.org/pypi/django-news
>>
>>
>> On Fri, Jul 4, 2014 at 9:43 PM, Elena Williams  wrote:
>>
>>> Hey everybody,
>>>
>>> &tldr; Looking for Journalists/former-Journalists/Journalism grads in
>>> the community for any advice they might have.
>>>
>>> I'm giving a talk at DjangoConAU more-or-less about communicating news
>>> in community.
>>>
>>> Django has a proud journalistic tradition and as such it seems remiss to
>>> *not* at least ask around amongst the actual news-communications trained
>>> people in the community for any advice or pointers they may have for this
>>> presentation (I need all the help I can get).
>>>
>>> I know our erstwhile-BDFLs were both journalism graduates, but:
>>>
>>>  * Does anyone know of any other journalist/news types in our community
>>> I should contact?
>>>
>>>  * Anyone have any notable news/journalism advice I should be passing
>>> along?
>>>
>>> Or, just contact me if you think there's anything I should mention, or
>>> have any friendly advice, thank you!
>>> ---
>>> Elena Williams :)
>>> @elequ
>>>
>>>  --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMRRKVd3GxcbgRLpzEhmwLQwD6f%3D_Mvt8hAiYbN1Gk91JCZTSg%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHXGZtqX5-oYaOgDrdmqyXyvt-KO50Rh00swoeq75JT44xeh%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple History - Field Change

2014-07-04 Thread Aaron Reabow
You are totally right.

There is a historical table that required deletion.

This is why you shouldn't debug late on friday afternoon.  I had actually 
looked for that table but somehow missed it.

I will pick up the broader problems with simple history separately.

thanks for taking the time to look through this Cal. 

On Friday, 4 July 2014 18:05:43 UTC+2, Cal Leeming [Simplicity Media Ltd] 
wrote:
>
> It sounds like you haven't applied the table changes to the cloned table 
> which it creates to track changes.
>
> I'd advice using something like South to manage your schema changes, and 
> this should work out of the box with django-simple-history. 
>
> For now, you can delete the cloned table and re-sync, you will naturally 
> lose the historical data but if you deleted the original then this probably 
> won't matter.
>
> It's also worth mentioning that the design approach 
> of django-simple-history is completely wrong, and personally I wouldn't 
> recommend using it. Feel free to start a separate thread if you'd like to 
> discuss that further though as it's slightly off topic for this thread.
>
> Let us know how you get on.
>
> Cal
>
>
> On Fri, Jul 4, 2014 at 4:47 PM, Aaron Reabow  > wrote:
>
>> Environment:
>>
>>
>> Request Method: POST
>> Request URL: upon request :)
>>
>> Django Version: 1.6.2
>> Python Version: 2.7.5
>> Installed Applications:
>> ('django.contrib.admin',
>>  'django.contrib.admindocs',
>>  'django.contrib.auth',
>>  'django.contrib.sites',
>>  'django.contrib.contenttypes',
>>  'django.contrib.sessions',
>>  'django.contrib.messages',
>>  'django.contrib.staticfiles',
>>  'myproject.ngc',
>>  'registration',
>>  'crispy_forms',
>>  'floppyforms',
>>  'simple_history')
>> Installed Middleware:
>> ('django.contrib.sessions.middleware.SessionMiddleware',
>>  'django.middleware.common.CommonMiddleware',
>>  'django.middleware.csrf.CsrfViewMiddleware',
>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>  'django.contrib.messages.middleware.MessageMiddleware',
>>  'django.middleware.clickjacking.XFrameOptionsMiddleware')
>>
>>
>> Traceback:
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/core/handlers/base.py"
>>  
>> in get_response
>>   114. response = wrapped_callback(request, 
>> *callback_args, **callback_kwargs)
>> File "/home/metadata/webapps/greenhouse/myproject/myproject/ngc/views.py" 
>> in leadManagementView
>>   540. model_instance.save()
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in save
>>   545.force_update=force_update, 
>> update_fields=update_fields)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in save_base
>>   582.update_fields=update_fields, 
>> raw=raw, using=using)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/dispatch/dispatcher.py"
>>  
>> in send
>>   185. response = receiver(signal=self, sender=sender, 
>> **named)
>> File 
>> "/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py" 
>> in post_save
>>   209. self.create_historical_record(instance, created and 
>> '+' or '~')
>> File 
>> "/home/metadata/.local/lib/python2.7/site-packages/simple_history/models.py" 
>> in create_historical_record
>>   222.history_user=history_user, **attrs)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py"
>>  
>> in create
>>   157. return self.get_queryset().create(**kwargs)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py" 
>> in create
>>   319. obj.save(force_insert=True, using=self.db)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in save
>>   545.force_update=force_update, 
>> update_fields=update_fields)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in save_base
>>   573. updated = self._save_table(raw, cls, force_insert, 
>> force_update, using, update_fields)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in _save_table
>>   654. result = self._do_insert(cls._base_manager, using, 
>> fields, update_pk, raw)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/base.py" 
>> in _do_insert
>>   687.using=using, raw=raw)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/manager.py"
>>  
>> in _insert
>>   232. return insert_query(self.model, objs, fields, **kwargs)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7/django/db/models/query.py" 
>> in insert_query
>>   1511. return query.get_compiler(using=using).execute_sql(return_id)
>> File 
>> "/home/metadata/webapps/greenhouse/lib/python2.7

Re: Unicode Str error [Beginner question]

2014-07-04 Thread Tom Evans
On Thu, Jul 3, 2014 at 8:08 PM, Lian Tombing  wrote:
> When I tried to implement the example,
>
> class Poll(models.Model):
> # ...
> def __unicode__(self):  # Python 3: def __str__(self):
> return self.question
>
> I get the error,
>
> Tab error: inconsistent use of tabs and spaces.

You must use either tabs or spaces to indent your code, not both tabs
and spaces. Configure your editor to output spaces instead of tab when
you press the tab key, and reindent your code.

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KWhUXXWoyaqAnX4%3DG0KmKu2AW%3DRRx8GZiAHqC1csL3Uw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Adding custom button to each field od ModelAdmib using Grappelli

2014-07-04 Thread Filip Bajaník


I use Grappelli as a custom admin sites plugin...

I use hard-coded button in list_display in the each field which looks like 
this

def approve_button(self):
return u"" % (_("Approve"), _("Are you sure you want to 
approve this request?"), self.id, self.license_ticket.id)
approve_button.allow_tags = True

The problem is, that I have list_editable ForeignKey and I want to choose 
an element from the list, hit the button and send self.license_ticket.id to 
/approve/%s/%s. Sending id is simple, but the list has to be saved after 
clicking on the Approve button.

One solution is to choose from the list, hit the Save button at the bottom 
of the page and then hit the Approve button, which is solution I don't like.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1cdd9410-1a74-4dd9-9071-7cbfe0843e74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.