Accessing the auth user object in a template?

2011-06-23 Thread Travis Bear
Hi,

I'm using the django.contrib.auth app to manage user login/logout.  I
can successfully log in and out, but I cannot access the {{ user }}
object in my templates.  If I'm reading these documents correctly,
that should be enabled by default:

@ zalun

http://stackoverflow.com/questions/41547/always-including-the-user-in-the-django-template-context

   
https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-data-in-templates

Am I missing something?  Here is a snippet from my base.html:

{% if user.is_authenticated %}
Welcome, {{ user.username }}. Thanks for logging in.
{% else %}
Welcome, new user. Please log in.
{% endif %}

If I I have my view explicity include the request.user object in the
template context, the above code works as expected.  But I don't want
to have to put this in every one of my view functions.

Here are the template context processors in my settings.py:

TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
   "django.core.context_processors.debug",
   "django.core.context_processors.i18n",
   "django.core.context_processors.media",
 
"django.core.context_processors.request",
)

Any insights appreciated.


Thanks!


-Travis

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



Re: Accessing the auth user object in a template?

2011-06-23 Thread Tom Evans
On Thu, Jun 23, 2011 at 8:28 AM, Travis Bear  wrote:
> Hi,
>
> I'm using the django.contrib.auth app to manage user login/logout.  I
> can successfully log in and out, but I cannot access the {{ user }}
> object in my templates.  If I'm reading these documents correctly,
> that should be enabled by default:
>
>    @ zalun
>    
> http://stackoverflow.com/questions/41547/always-including-the-user-in-the-django-template-context
>
>   
> https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-data-in-templates
>
> Am I missing something?  Here is a snippet from my base.html:
>
> {% if user.is_authenticated %}
>    Welcome, {{ user.username }}. Thanks for logging in.
> {% else %}
>    Welcome, new user. Please log in.
> {% endif %}
>
> If I I have my view explicity include the request.user object in the
> template context, the above code works as expected.  But I don't want
> to have to put this in every one of my view functions.
>
> Here are the template context processors in my settings.py:
>
> TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
>                               "django.core.context_processors.debug",
>                               "django.core.context_processors.i18n",
>                               "django.core.context_processors.media",
>
> "django.core.context_processors.request",
> )
>
> Any insights appreciated.
>


You aren't rendering the template with a RequestContext, so
TEMPLATE_CONTEXT_PROCESSORS doesn't come into play.


Cheers

Tom

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



Re: manytomany query problem

2011-06-23 Thread Nikhil Somaru
It is very hard to read your message. Please format it appropriately next
time. Avoid repeating variable names and mixing classes with instances.
Could you post your models here?

Are you defining the following structure:

A hasMany B;
B hasMany A;
B hasMany B;

So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.

On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:

> I have two models with a manytomany through relation (A and B).  B has
> a self referential manytomany relation (a userprofile model).  How
> could I filter objects of model B per each relationship with model A?
> So lets say 3 arbitrary model A objects have 20 model B object
> relations each.  I want to filter the relations so when I return the
> filtered version of model A is outputted, each object of type model A
> returns only object Bs (the userprofiles) that are connected through
> the self referential manytomany relationship to the userprofile (the
> object B, sorry if I use them interchangeably but they are the same
> thing) that is currently sending in the request.  I figure out which
> userprofile is sending the request with a unique identifier sent by
> the user in the request (basically their primary key).  Is this type
> of filtering possible.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Yours,
Nikhil Somaru

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



create_inactive_user() got an unexpected keyword argument 'profile_callback' Error in django registration . What can be the error ?

2011-06-23 Thread Satyajit Sarangi
This is my stack trace .

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/registration/views.py" in
register
  144. new_user =
form.save(profile_callback=profile_callback)
File "/usr/local/lib/python2.6/dist-packages/registration/forms.py" in
save
  88.send_email = False)
File "/usr/local/lib/python2.6/dist-packages/django/db/transaction.py"
in inner
  217. res = func(*args, **kwargs)

Exception Type: TypeError at /accounts/register/
Exception Value: create_inactive_user() got an unexpected keyword
argument 'profile_callback'


How to get rid of this error ?

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



Haystack No site conf error . How to debug ?

2011-06-23 Thread Satyajit Sarangi
This is my settings.py

# Django global settings

# This allows us to construct the needed absolute paths dynamically,
# e.g., for the GIS_DATA_DIR, MEDIA_ROOT, and TEMPLATE_DIRS settings.
# see: http://rob.cogit8.org/blog/2008/Jun/20/django-and-relativity/
import os
GEOGRAPHIC_ADMIN_DIR = os.path.dirname(__file__)

# http://docs.djangoproject.com/en/dev/topics/testing/#id1
# Your user must be a postgrest superuser
# Avoid specifying your password with: ~/.pgpass
# http://www.postgresql.org/docs/8.3/interactive/libpq-pgpass.html
TEST_RUNNER='django.contrib.gis.tests.run_gis_tests'

DEBUG=True

ADMINS = (
# ('Your Name', 'your_em...@domain.com'),
)

DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'geoadmin'
DATABASE_USER = 'postgres' # make sure to change this to your postgres
user
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

# Not used at this point but you'll need it here if you
# want to enable a google maps baselayer within your
# OpenLayers maps
GOOGLE_MAPS_API_KEY='abcdefg'

SHP_UPLOAD_DIR = r"/home/satyajit/geodjango/geographic_admin/data"
GIS_DATA_DIR = os.path.join(GEOGRAPHIC_ADMIN_DIR, 'data')

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Vancouver'

SITE_ID = 1

USE_I18N = True

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

MEDIA_URL = '/media/'

HAYSTACK_SITECONF='geographic_admin.search_sites'

HAYSTACK_SEARCH_ENGINE = 'xapian'
HAYSTACK_WHOOSH_PATH = '/home/satyajit/geodjango/geographic_admin/
xapian-index'


ADMIN_MEDIA_PREFIX = '/admin_media/'
LOGIN_REDIRECT_URL = '/accounts/profile/'
SECRET_KEY = '2f!vq4!f)u#g-sk7_=z+i0e(o0o&hue5khxbdkdx$f%hvpb^vd'
LOGIN_URL='/accounts/login/'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
)

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
 'django.core.context_processors.request',
 'django.core.context_processors.debug',
 'django.core.context_processors.i18n',
 'django.core.context_processors.media',
 'django.core.context_processors.static',
 'django.contrib.auth.context_processors.auth',
 'django.contrib.messages.context_processors.messages',

)
AUTH_PROFILE_MODULE = 'userprofile.profile'
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

ROOT_URLCONF = 'urls'
STATIC_URL = '/static/'
STATIC_ROOT = "/home/satyajit/geodjango/geographic_admin/sitestatic"

if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'

TEMPLATE_DIRS = (
os.path.join(GEOGRAPHIC_ADMIN_DIR, 'templates'),
os.path.join(GEOGRAPHIC_ADMIN_DIR, '../registration/templates'),

# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.databrowse',
'django.contrib.gis',
'django.contrib.staticfiles',
'world',
'maps',
'shapes',
'registration',
'waypoints',
'openmaps',
'permissions',
'floppyforms',
'OsmMap',
'userprofile',
'mapsearch',
'haystack',

)

ACCOUNT_ACTIVATION_DAYS=7
EMAIL_HOST='localhost'
EMAIL_PORT=1023
EMAIL_HOST_USER='username'
EMAIL_HOST_PASSWORD='password'

The error I get is this
  raise ImproperlyConfigured('The HAYSTACK_SITECONF setting is no
longer used & can be removed.')
django.core.exceptions.ImproperlyConfigured: The HAYSTACK_SITECONF
setting is no longer used & can be removed.

The error when I remove HAYSTACK_SITECONF is this
django.core.exceptions.ImproperlyConfigured: The
HAYSTACK_SEARCH_ENGINE setting has been replaced with
HAYSTACK_CONNECTIONS.

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



Re: django page loads forever

2011-06-23 Thread Nikhil Somaru
for a quick fix you could also

import pdb
pdb.set_trace()

that will drop a shell in your "runserver" window and let you explore the
value of variables in the context

On Wed, Jun 22, 2011 at 8:59 PM, Shawn Milochik  wrote:

> On 06/22/2011 11:26 AM, jay K. wrote:
>
>> Hello, everyone
>>
>> I have a django page which loads indefinitely
>>
>> some of the javascript that is supposed to come up does not appear on
>> the screen (while
>> the page is still loading), but i checked with firebugs and there are
>> no error messages at all
>>
>> any advice would be helpful
>>
>> thanks
>>
>> jay k
>>
>>  Put some logging statements in the view and see if it finishes. Instead
> of just returning your render or render_to_response, assign it to a
> variable, print it out in the log, then return the variable.
>
> This will help you determine whether the problem is in the view (view logic
> or template rendering) or a JS/other problem in your browser.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>


-- 
Yours,
Nikhil Somaru

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Władysław Mettler
Definitely interested. Struggling with scaling a 
Django/Celery/Postgres/CouchDB/Memcach project now. Would love to see your 
approach.

Cheers
Vlad

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



Returning a 503 response instead of a 500 response

2011-06-23 Thread Steven L Smith
Some of our apps have to talk to databases outside of our control, and their 
operators don't have the same uptime standards that we do...

What can I do to make Django return a "503 Service Unavailable" instead of a 
"500 Internal Server Error", when it encounters a DatabaseError or 
ProgrammingError while trying to access the database? Bonus points if I could 
make the 503 page say "there was a temporary database communication problem."

I have some ideas of what I *could* modify, but I'd rather incorporate this 
into a product or setting instead of having to patch the actual django database 
backend code itself.


Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085 | ssmit...@naz.edu | KC2YTC
http://www.naz.edu/pub/~ssmith46


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



Re: django page loads forever

2011-06-23 Thread Shawn Milochik

On 06/23/2011 05:05 AM, Nikhil Somaru wrote:

for a quick fix you could also

import pdb
pdb.set_trace()

that will drop a shell in your "runserver" window and let you explore 
the value of variables in the context




+1 on pdb

http://www.doughellmann.com/PyMOTW/pdb/


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



Re: create_inactive_user() got an unexpected keyword argument 'profile_callback' Error in django registration . What can be the error ?

2011-06-23 Thread Shawn Milochik
It looks like you added an extra kwarg named profile_callback to a 
function call to use in your overridden version, then passed *kwargs on 
to the original version. Before you call the super() version you have to 
pop off your kwarg because it is an invalid parameter for the original 
version.



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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread higs
> If you're interested, please reply on-list so others can see.
>
would love to see this. thanks for posting.

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



Re: Returning a 503 response instead of a 500 response

2011-06-23 Thread Tom Evans
On Thu, Jun 23, 2011 at 2:19 PM, Steven L Smith  wrote:
> Some of our apps have to talk to databases outside of our control, and their 
> operators don't have the same uptime standards that we do...
>
> What can I do to make Django return a "503 Service Unavailable" instead of a 
> "500 Internal Server Error", when it encounters a DatabaseError or 
> ProgrammingError while trying to access the database? Bonus points if I could 
> make the 503 page say "there was a temporary database communication problem."
>
> I have some ideas of what I *could* modify, but I'd rather incorporate this 
> into a product or setting instead of having to patch the actual django 
> database backend code itself.
>

Exception handling is performed by middleware. When a django view
encounters an un-handled exception, each installed middleware class is
asked if it wants to handle this exception. If none do, Django sends
out it's pre-canned response as it sees fit.

So, simply write your own exception handling middleware that handles
DatabaseError or ProgrammingError, and passes on other errors. See the
docs for more details:

https://docs.djangoproject.com/en/1.3/topics/http/middleware/#process-exception

Cheers

Tom

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



Re: Returning a 503 response instead of a 500 response

2011-06-23 Thread Steven L Smith
Neat. I've been doing Django since the 0.9.6 days and have never written a 
middleware. I guess there's a first time for everything.

Thanks!


Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085 | ssmit...@naz.edu | KC2YTC
http://www.naz.edu/pub/~ssmith46


- Original Message -
From: "Tom Evans" 
To: django-users@googlegroups.com
Sent: Thursday, June 23, 2011 9:28:15 AM GMT -05:00 US/Canada Eastern
Subject: Re: Returning a 503 response instead of a 500 response

On Thu, Jun 23, 2011 at 2:19 PM, Steven L Smith  wrote:
> Some of our apps have to talk to databases outside of our control, and their 
> operators don't have the same uptime standards that we do...
>
> What can I do to make Django return a "503 Service Unavailable" instead of a 
> "500 Internal Server Error", when it encounters a DatabaseError or 
> ProgrammingError while trying to access the database? Bonus points if I could 
> make the 503 page say "there was a temporary database communication problem."
>
> I have some ideas of what I *could* modify, but I'd rather incorporate this 
> into a product or setting instead of having to patch the actual django 
> database backend code itself.
>

Exception handling is performed by middleware. When a django view
encounters an un-handled exception, each installed middleware class is
asked if it wants to handle this exception. If none do, Django sends
out it's pre-canned response as it sees fit.

So, simply write your own exception handling middleware that handles
DatabaseError or ProgrammingError, and passes on other errors. See the
docs for more details:

https://docs.djangoproject.com/en/1.3/topics/http/middleware/#process-exception

Cheers

Tom

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

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Derek
Carl

Please post here when the recording becomes available... some of us do
not have access to HD-capable bandwidth yet!

Thanks
Derek

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
First, if, despite being related by inheritance, Word and Verb are
separate models, they have separate tables.  Then if you do create
a Verb, the Word still exists, unless you delete it.  Is that what you
want?  If both are to exist, were you hoping that a query for the
same key would still find the Word, or do you want it to find the Verb.
And how do you want to treat words (if text words they are) like "record",
which is a noun (keep a record), a verb (record a performance) and an
adjective (record crowd), at the very least.  (Note that the pronunciation
of the verb is different, if you were thinking of storing pronunciation info
in the Word.)

If you have separate models, you could certainly write the method that
initializes a completely separate sub-class instance from the instance
data of the super class instance.  You could also do some magic using
the field list available in the manager (which has the problem, IIRC, that
it is not a public interface) to know which data to copy, though I'm of the
explicit is better than implicit camp.

So, I guess that I really don't know enough about your problem to
suggest a detailed technique.  I suspect that if it were me, I'd probably
be using a foreign key reference from Verb to Word, rather than
sub-classing.

Bill

On Wed, Jun 22, 2011 at 9:45 PM, Matt Gardner  wrote:
> Hello all,
>
> I have a model hierarchy in my django app, and there is one very
> important task that I do not know how to do.  I have a bunch of
> instances of the superclass (Word is the model name), and on input
> from a user I want to create a subclass instance (Verb) from that
> superclass instance.  For example, I might have code like this:
>
 word = Word.objects.get(pk=[input from user])
 verb = Verb.createFromSuperclassInstance(word)
 verb.save()
>
> The only problem is that I know of no such
> "createFromSuperclassInstance" method, nor where to look for it.  I do
> know how to do this through the database itself (just add a row to the
> verb table with the correct foreign key), but I was hoping django
> would provide some nice way to do it without me having to explicitly
> write SQL.  The Verb class's __init__ method creates a new Word
> instance, so that doesn't work, unless there's a way to use it that I
> don't know about.
>
> Any help?
>
> Thanks,
> Matt
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Errors saving blank Admin Inline with FilePathField?

2011-06-23 Thread Nan
This is driving me batty...

Because there's no blank option in the form field for a FilePathField
with blank=False, then if you:

- Have an Admin Inline with a FilePathField and another required field
- Have extra (i.e. intentionally blank) inlines in your form

You will get an error upon saving because the FilePathField is not
blank but the other fields are, and so the formset thinks you're
trying to save those objects but have left the other required fields
blank.

Is there *any* workaround for this?

Thanks,
-Nan

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
Hi Derek,

I've had a look and apparently 4-5mbit should be sufficient enough for a HD
webinar. If quite a few of you don't have this capability (or screen size),
I could look into reducing it down to 1440x900 perhaps?

Let me know your thoughts guys. (maybe it's something I need to do a web
vote for, along with the timezone etc)

Cal

On Thu, Jun 23, 2011 at 2:55 PM, Derek  wrote:

> Carl
>
> Please post here when the recording becomes available... some of us do
> not have access to HD-capable bandwidth yet!
>
> Thanks
> Derek
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



I have two doubts when It comes to django url and django templates . Please help

2011-06-23 Thread Satyajit Sarangi
{% extends "base.html" %}

{% load i18n %}
Hello User {{user}}
{% block content %}
{% if form.errors %}
{% trans "Sorry there are corrections needed
in your form below:" %} {{ form.non_field_errors }}
{% endif %}
{% if form.is_multipart %}

Hello User {{user}}
{% else %}

   {% endif %}
   {{ form.as_p }}
   
   
{% endblock %}

This is a template of mine . It is not displaying Hello User . What
can be the error ?


The other doubt is this .


Create a map with OsmMap as
baselayer This is a link on one of my templates .
Osmmaps.html is a template that displays a form comprising of a OSM
layers .

Both are in different apps .

Thus when I try to link it , this is the error I get
Reverse for 'Osmmaps' with arguments '()' and keyword arguments '{}'
not found.


I am very new to django , and am finding the django documentation on
the url a bit too difficult . Do help

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Chris Calitz
Sounds really cool. I'm definitely in. 

On 22 Jun 2011, at 14:16, "Cal Leeming [Simplicity Media Ltd]" 
 wrote:

> Hi all,
> 
> Some of you may have noticed, in the last few months I've done quite a few 
> posts/snippets about handling large data sets in Django. At the end of this 
> month (after what seems like a lifetime of trial and error), we're finally 
> going to be releasing a new site which holds around 40mil+ rows of data, 
> grows by about 300-500k rows each day, handles 5GB of uploads per day, and 
> can handle around 1024 requests per second on stress test on a moderately 
> spec'd server.
> 
> As the entire thing is written in Django (and a bunch of other open source 
> products), I'd really like to give something back to the community. (stack 
> incls Celery/RabbitMQ/Sphinx SE/PYQuery/Percona 
> MySQL/NGINX/supervisord/debian etc)
> 
> Therefore, I'd like to see if there would be any interest in webcast in which 
> I would explain how we handle such large amounts of data, the trial and error 
> processes we went through, some really neat tricks we've done to avoid 
> bottlenecks, our own approach to smart content filtering, and some of the 
> valuable lessons we have learned. The webcast would be completely free of 
> charge, last a couple of hours (with a short break) and anyone can attend. 
> I'd also offer up a Q&A session at the end.
> 
> If you're interested, please reply on-list so others can see.
> 
> Thanks
> 
> Cal
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread John DeRosa
Me

On Jun 23, 2011, at 7:49, Chris Calitz  wrote:

> Sounds really cool. I'm definitely in. 
> 
> On 22 Jun 2011, at 14:16, "Cal Leeming [Simplicity Media Ltd]" 
>  wrote:
> 
>> Hi all,
>> 
>> Some of you may have noticed, in the last few months I've done quite a few 
>> posts/snippets about handling large data sets in Django. At the end of this 
>> month (after what seems like a lifetime of trial and error), we're finally 
>> going to be releasing a new site which holds around 40mil+ rows of data, 
>> grows by about 300-500k rows each day, handles 5GB of uploads per day, and 
>> can handle around 1024 requests per second on stress test on a moderately 
>> spec'd server.
>> 
>> As the entire thing is written in Django (and a bunch of other open source 
>> products), I'd really like to give something back to the community. (stack 
>> incls Celery/RabbitMQ/Sphinx SE/PYQuery/Percona 
>> MySQL/NGINX/supervisord/debian etc)
>> 
>> Therefore, I'd like to see if there would be any interest in webcast in 
>> which I would explain how we handle such large amounts of data, the trial 
>> and error processes we went through, some really neat tricks we've done to 
>> avoid bottlenecks, our own approach to smart content filtering, and some of 
>> the valuable lessons we have learned. The webcast would be completely free 
>> of charge, last a couple of hours (with a short break) and anyone can 
>> attend. I'd also offer up a Q&A session at the end.
>> 
>> If you're interested, please reply on-list so others can see.
>> 
>> Thanks
>> 
>> Cal
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: I have two doubts when It comes to django url and django templates . Please help

2011-06-23 Thread Tom Evans
On Thu, Jun 23, 2011 at 3:52 PM, Satyajit Sarangi
 wrote:
> {% extends "base.html" %}
>
> {% load i18n %}
> Hello User {{user}}
> {% block content %}
>    {% if form.errors %}
>    {% trans "Sorry there are corrections needed
> in your form below:" %} {{ form.non_field_errors }}
>    {% endif %}
>    {% if form.is_multipart %}
>    
>    Hello User {{user}}
>    {% else %}
>    
>   {% endif %}
>   {{ form.as_p }}
>   
>   
> {% endblock %}
>
> This is a template of mine . It is not displaying Hello User . What
> can be the error ?

Template inheritance replaces the blocks in the parent with the blocks
in the child template with the same name. Where you output 'Hello
User' is outside of any named blocks, so is ignored. Read the docs:

https://docs.djangoproject.com/en/1.3/topics/templates/#template-inheritance

>
>
> The other doubt is this .
>
>
> Create a map with OsmMap as
> baselayer This is a link on one of my templates .
> Osmmaps.html is a template that displays a form comprising of a OSM
> layers .
>
> Both are in different apps .
>
> Thus when I try to link it , this is the error I get
> Reverse for 'Osmmaps' with arguments '()' and keyword arguments '{}'
> not found.
>

The {% url %} tag takes either a view reference (eg
'myapp.views.something') or a view name, as configured when the URL
for that view is configured in your urls.py. It does not take a HTML
template name with '.html' stripped off the end. Again, docs:

https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#url
https://docs.djangoproject.com/en/1.3/topics/http/urls/
https://docs.djangoproject.com/en/1.3/topics/http/urls/#naming-url-patterns

Cheers

Tom

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



Best way of rendernig ""dynamic"" templates

2011-06-23 Thread Marc Aymerich
Hi,
I'm deveolping some reusable apps with the aim of generating apache
config files.
The schema is: one 'base' app called apache and an arbitrary number of
apps that act as OPTIONAL extensions.

These extension apps fit with base app on django-admin as inlines
forms, and the template is rendered when all inlines are saved.

My question is,
What is the best way to render the apache template considering that an
arbitrary number of extensions can fit some lines in multiple places
of it?

Thanks!

Example:

# Apache APP
# VirtualHost template

# Apache app lines
# 
# 
# VH EXTENSION LINES

# EXTENSION LINES OUT OF 

# "PHP Extension" APP
# PHP Extension Template
# This should go inside  
Action php-fcgi /fcgi-bin/php-fcgi-wrapper
Alias /fcgi-bin/ {{ object.default_fcgid_basedir }}/{{
object.version }}-{{ object.virtualhost.user.name }}/
# Other lines that doesn't go inside  definition
# 

# "Python Extension" APP
# Python Extension Template
# This should go inside  definition

SetHandler fastcgi-script

# Other lines that doesn't go inside  
# ...

-- 
Marc

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



Re: Test runner fails with Django 1.2.1 and psycopg2 2.4.2

2011-06-23 Thread ashwoods
do you get these errors with:

'OPTIONS': {
'autocommit': True,
}

?

On Jun 14, 6:06 pm, Andrew Brookins  wrote:
> Hey,
>
> Yesterday I started seeing test runner failures with Django 1.2.1 and
> psycog2 2.4.2.
>
> Here's the traceback (where [project_dir] is the path to my virtualenv):
>
> Traceback (most recent call last):
>   File "./manage.py", line 11, in 
>     execute_manager(settings)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/core/management/__init__. 
> py",
> line 438, in execute_manager
>     utility.execute()
>   File
> "[project_dir]/lib/python2.6/site-packages/django/core/management/__init__. 
> py",
> line 379, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/core/management/base.py",
> line 191, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/core/management/base.py",
> line 218, in execute
>     output = self.handle(*args, **options)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/core/management/commands/ 
> test.py",
> line 37, in handle
>     failures = test_runner.run_tests(test_labels)
>   File "[project_dir]/lib/python2.6/site-packages/django/test/simple.py",
> line 313, in run_tests
>     old_config = self.setup_databases()
>   File "[project_dir]/lib/python2.6/site-packages/django/test/simple.py",
> line 270, in setup_databases
>     connection.creation.create_test_db(self.verbosity, autoclobber=not
> self.interactive)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/db/backends/creation.py",
> line 346, in create_test_db
>     test_database_name = self._create_test_db(verbosity, autoclobber)
>   File
> "[project_dir]/lib/python2.6/site-packages/django/db/backends/creation.py",
> line 381, in _create_test_db
>     self.set_autocommit()
>   File
> "[project_dir]/lib/python2.6/site-packages/django/db/backends/creation.py",
> line 448, in set_autocommit
>     self.connection.connection.autocommit = True
> psycopg2.ProgrammingError: autocommit cannot be used inside a transaction
>
> Reverting to psycopg2 2.4.1 fixes the problem. Anyone seen this?
>
> Best,
> Andrew

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



Re: Errors saving blank Admin Inline with FilePathField?

2011-06-23 Thread Nan

For the reference of future generations, the following seems to work:

class MyAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyAdminForm, self).__init__(*args, **kwargs)
self.fields['some_fpath_field'].choices = [('','--'),] +
self.fields['some_fpath_field'].choices


class MyInline(models.TabularInline):
form = MyAdminForm


On Jun 23, 10:43 am, Nan  wrote:
> This is driving me batty...
>
> Because there's no blank option in the form field for a FilePathField
> with blank=False, then if you:
>
> - Have an Admin Inline with a FilePathField and another required field
> - Have extra (i.e. intentionally blank) inlines in your form
>
> You will get an error upon saving because the FilePathField is not
> blank but the other fields are, and so the formset thinks you're
> trying to save those objects but have left the other required fields
> blank.
>
> Is there *any* workaround for this?
>
> Thanks,
> -Nan

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



Re: manytomany query problem

2011-06-23 Thread Tony
You have the question I was asking correct, your notation was fine.
The only thing I should add is I want to return all A, but filter  my
"B1"s (as you put it) for each A. I will post my models if need be,
but they are on another computer and its not convenient right now.  In
the meantime, do you have any ideas for this query?

On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> It is very hard to read your message. Please format it appropriately next
> time. Avoid repeating variable names and mixing classes with instances.
> Could you post your models here?
>
> Are you defining the following structure:
>
> A hasMany B;
> B hasMany A;
> B hasMany B;
>
> So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.
>
>
>
> On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > I have two models with a manytomany through relation (A and B).  B has
> > a self referential manytomany relation (a userprofile model).  How
> > could I filter objects of model B per each relationship with model A?
> > So lets say 3 arbitrary model A objects have 20 model B object
> > relations each.  I want to filter the relations so when I return the
> > filtered version of model A is outputted, each object of type model A
> > returns only object Bs (the userprofiles) that are connected through
> > the self referential manytomany relationship to the userprofile (the
> > object B, sorry if I use them interchangeably but they are the same
> > thing) that is currently sending in the request.  I figure out which
> > userprofile is sending the request with a unique identifier sent by
> > the user in the request (basically their primary key).  Is this type
> > of filtering possible.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Yours,
> Nikhil Somaru

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
Thanks, Bill, for your comments.

Shortly after I posted here I did a little more digging and found this
thread from six months ago that described exactly my problem:

http://groups.google.com/group/django-users/browse_thread/thread/9400999651577bc2/8cc4fe267128d6a3

That thread didn't seem to have a good solution, though...

As far as whether I should have done inheritance or composition, that's a
fair question that could have gone either way.  But I chose inheritance a
while ago, as it seemed to make the most sense for what I am doing, and
that's the way the code is written.  At several points in my code, I have
blocks that do things like this:

try:
verb = word.verb
# do verb-specific stuff
except Verb.DoesNotExist:
pass

I deal with a collection of words most of the time, and if they are also
verbs I add some additional stuff.

At this point, all I really want to do is add a row to the verb table that
contains the correct foreign key, without creating a new row in the word
table.  And I don't want to write SQL to do it, though if I don't find
another solution, that's what I'm going to do, because it's fairly
straightforward to just do that.  Also, I want to be able to delete just the
verb part, which is just deleting the row in the verb table and all
corresponding information (i.e., some other tables reference verb but not
word, so on deleting the verb row you want to delete the references to it).

And, now that I look at this, it seems that composition would have
simplified those two things, as django makes that nice and easy (with a
one-to-one field in Verb).  If I can figure out a nice way to do it while
keeping inheritance, it would make my life easier, as I already have a bunch
of code written and databases that I don't want to repair that use
inheritance.  But, given that it looks like composition would probably be
easier, maybe I should just take the hit and convert everything?  Thoughts?

On Thu, Jun 23, 2011 at 10:09 AM, Bill Freeman  wrote:

> First, if, despite being related by inheritance, Word and Verb are
> separate models, they have separate tables.  Then if you do create
> a Verb, the Word still exists, unless you delete it.  Is that what you
> want?  If both are to exist, were you hoping that a query for the
> same key would still find the Word, or do you want it to find the Verb.
> And how do you want to treat words (if text words they are) like "record",
> which is a noun (keep a record), a verb (record a performance) and an
> adjective (record crowd), at the very least.  (Note that the pronunciation
> of the verb is different, if you were thinking of storing pronunciation
> info
> in the Word.)
>
> If you have separate models, you could certainly write the method that
> initializes a completely separate sub-class instance from the instance
> data of the super class instance.  You could also do some magic using
> the field list available in the manager (which has the problem, IIRC, that
> it is not a public interface) to know which data to copy, though I'm of the
> explicit is better than implicit camp.
>
> So, I guess that I really don't know enough about your problem to
> suggest a detailed technique.  I suspect that if it were me, I'd probably
> be using a foreign key reference from Verb to Word, rather than
> sub-classing.
>
> Bill
>
> On Wed, Jun 22, 2011 at 9:45 PM, Matt Gardner  wrote:
> > Hello all,
> >
> > I have a model hierarchy in my django app, and there is one very
> > important task that I do not know how to do.  I have a bunch of
> > instances of the superclass (Word is the model name), and on input
> > from a user I want to create a subclass instance (Verb) from that
> > superclass instance.  For example, I might have code like this:
> >
>  word = Word.objects.get(pk=[input from user])
>  verb = Verb.createFromSuperclassInstance(word)
>  verb.save()
> >
> > The only problem is that I know of no such
> > "createFromSuperclassInstance" method, nor where to look for it.  I do
> > know how to do this through the database itself (just add a row to the
> > verb table with the correct foreign key), but I was hoping django
> > would provide some nice way to do it without me having to explicitly
> > write SQL.  The Verb class's __init__ method creates a new Word
> > instance, so that doesn't work, unless there's a way to use it that I
> > don't know about.
> >
> > Any help?
> >
> > Thanks,
> > Matt
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Tom Evans
On Thu, Jun 23, 2011 at 4:36 PM, Matthew Gardner  wrote:
> At this point, all I really want to do is add a row to the verb table that
> contains the correct foreign key, without creating a new row in the word
> table.

Verb.objects.create(word=word) doesn't fulfill these criteria?

Cheers

Tom

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
The perfect link to refer these users to:

http://www.catb.org/~esr/faqs/smart-questions.html

(props to harryr for finding this)

On Mon, Jun 20, 2011 at 10:32 PM, Shawn Milochik  wrote:

> Is it just me or are we having a sudden spurt of e-mail that goes like
> this:
>
>Q: How do I 
>A: You do X.
>
>Q: How do I do X?
>A: You use Y.
>
>Q: How do I use Y?
>
> I'm convinced that these people are either trolls or inherently
> "un-helpable," unless you want to write their code for them.
>
> In either case I think the only sane response is to completely ignore these
> people as soon as this pattern emerges, because it's an utter waste of the
> time we could be using to help others -- the reason we're on this list in
> the first place.
>
> Also, ignoring them is probably the only way to discourage repeat offences.
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
On Thu, Jun 23, 2011 at 11:47 AM, Tom Evans wrote:

> On Thu, Jun 23, 2011 at 4:36 PM, Matthew Gardner  wrote:
> > At this point, all I really want to do is add a row to the verb table
> that
> > contains the correct foreign key, without creating a new row in the word
> > table.
>
> Verb.objects.create(word=word) doesn't fulfill these criteria?
>
When I run that, I get "TypeError: 'word' is an invalid keyword argument for
this function."  So, nope, unless I'm doing something wrong.  Note that Verb
*inherits *from Word, so there is no explicit "word" field in Verb.

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Shawn Milochik

On 06/23/2011 12:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:

The perfect link to refer these users to:

http://www.catb.org/~esr/faqs/smart-questions.html 



(props to harryr for finding this)



Yeah. I used to post that link pretty frequently until I was asked to 
stop. ;o)


I still think it's a great essay. If I remember correctly, the objection 
to it was that the tone wasn't necessarily at the same level of 
acceptance and friendliness we like to maintain in this group.


We should distill it into a shorter, newbie-friendly version and get it 
posted somewhere official so we can refer to it.



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



Re: Social Networking basics? -Raj

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
On Thu, Jun 23, 2011 at 5:46 PM, Shawn Milochik  wrote:

> On 06/23/2011 12:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:
>
>> The perfect link to refer these users to:
>>
>> http://www.catb.org/~esr/faqs/**smart-questions.html<
>> http://www.catb.org/%7Eesr/**faqs/smart-questions.html
>> >
>>
>>
>> (props to harryr for finding this)
>>
>>
> Yeah. I used to post that link pretty frequently until I was asked to stop.
> ;o)
>

Lmao, I won't re-post this again then ;p


>
> I still think it's a great essay. If I remember correctly, the objection to
> it was that the tone wasn't necessarily at the same level of acceptance and
> friendliness we like to maintain in this group.
>
> We should distill it into a shorter, newbie-friendly version and get it
> posted somewhere official so we can refer to it.


That's be pretty cool. But my guess is that the maintainers just want us to
reply with a "you need to give us more information before we can help you"
speech, in a non-insulting tone. Shame, takes all the fun out of it lol.




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

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



FileField model question

2011-06-23 Thread raj
I was reading https://docs.djangoproject.com/en/1.3/topics/http/file-uploads/,
and I got a little confused when looking at the handle_uploaded_file
function.

def handle_uploaded_file(f):
destination = open('some/file/name.txt', 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()

in the destination line, it refers to a specific text file. I don't
understand how this function is universal to all files if this is the
case. Shouldn't the destination be a simple path? like open('some/
file/', 'wb+)? Also, if I want the files to be organized in such a way
that each user gets their files uploaded to their own folder, where
would this part of the code go?
I was thinking the following:

def handle_uploaded_file(f, user):
destination = open("%s/documents/" %user, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()

Thank you.

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



Re: FileField model question

2011-06-23 Thread Herman Schistad
On Thu, Jun 23, 2011 at 18:51, raj  wrote:
> I was reading https://docs.djangoproject.com/en/1.3/topics/http/file-uploads/,
> and I got a little confused when looking at the handle_uploaded_file
> function.

You should read:
https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

And a simple google search on "handle uploaded file django" gives this
useful snippet:
http://djangosnippets.org/snippets/1036/

Did you search google before asking? :-)

-- 
With regards, Herman Schistad

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Steve Holden
And, as luck would have it, the US Call For Papers was just published:

  http://djangocon.us/blog/2011/06/22/call-papers/

regards
 Steve

On Wed, Jun 22, 2011 at 9:37 AM, Shawn Milochik  wrote:

> Cal,
>
> That sounds awesome. I wish you could present it at DjangoCon US too. :o/
>
> Shawn
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>


-- 
Steve Holden+1 571 484 6266  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
(sorry, should have sent this reply on-list)

You know, I was actually thinking about that, but the flights would cost way
too much (like $1400+) ;/ If the project has interest next year, I'll
probably ask about presenting at DjangoCon EU though.

On Thu, Jun 23, 2011 at 6:13 PM, Steve Holden  wrote:

> And, as luck would have it, the US Call For Papers was just published:
>
>   http://djangocon.us/blog/2011/06/22/call-papers/
>
> regards
>  Steve
>
> On Wed, Jun 22, 2011 at 9:37 AM, Shawn Milochik wrote:
>
>> Cal,
>>
>> That sounds awesome. I wish you could present it at DjangoCon US too. :o/
>>
>> Shawn
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to django-users+unsubscribe@**
>> googlegroups.com .
>> For more options, visit this group at http://groups.google.com/**
>> group/django-users?hl=en
>> .
>>
>>
>
>
> --
> Steve Holden+1 571 484 6266  +1 800 494 3119
> Holden Web LLC http://www.holdenweb.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Jason
+1 Very interested.

On Jun 22, 3:47 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> Nice, seems like there is a lot of positive feedback.
>
> Here's some further info about the webcast/webinar:
>
> *Expected Date:* July/August
> *Expected Time:* Somewhere between 9AM - 9PM GMT+0 (UK Time), I'll probably
> run a webpage vote so you guys can decide.
> *Via:* GoToWebinar - screen share with voip.
> *Length:* 1 hour max for actual presentation, 5 minute break, then another 1
> hour max for Q&As.
> *Presentation Size: *1920x1080 (1080p)
>
> There will be some basic slides (to keep things structured), but the
> majority of the time will be spent inside the browser + IDE + shell etc.
>
> Cal
>
> On Wed, Jun 22, 2011 at 10:49 PM, Mishen'ka 
> wrote:
>
>
>
>
>
>
>
> > I really like the idea, hope i can see it soon.
>
> > Interessting thanks
>
> > On 22 jun, 15:15, "Cal Leeming [Simplicity Media Ltd]"
> >  wrote:
> > > Hi all,
>
> > > Some of you may have noticed, in the last few months I've done quite a
> > few
> > > posts/snippets about handling large data sets in Django. At the end of
> > this
> > > month (after what seems like a lifetime of trial and error), we're
> > finally
> > > going to be releasing a new site which holds around 40mil+ rows of data,
> > > grows by about 300-500k rows each day, handles 5GB of uploads per day,
> > and
> > > can handle around 1024 requests per second on stress test on a moderately
> > > spec'd server.
>
> > > As the entire thing is written in Django (and a bunch of other open
> > source
> > > products), I'd really like to give something back to the community.
> > (stack
> > > incls Celery/RabbitMQ/Sphinx SE/PYQuery/Percona
> > > MySQL/NGINX/supervisord/debian etc)
>
> > > Therefore, I'd like to see if there would be any interest in webcast in
> > > which I would explain how we handle such large amounts of data, the trial
> > > and error processes we went through, some really neat tricks we've done
> > to
> > > avoid bottlenecks, our own approach to smart content filtering, and some
> > of
> > > the valuable lessons we have learned. The webcast would be completely
> > free
> > > of charge, last a couple of hours (with a short break) and anyone can
> > > attend. I'd also offer up a Q&A session at the end.
>
> > > If you're interested, please reply on-list so others can see.
>
> > > Thanks
>
> > > Cal
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
On Thu, Jun 23, 2011 at 2:18 PM, Matthew Gardner  wrote:

> class Verb(models.Model):
> word = models.ForeignKey('Word')
> # Verb-specific stuff
>

Sorry, this is more accurate:

class Verb(models.Model):
word = models.OneToOneField('Word')
# verb-specific stuff

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



Re: Accessing the auth user object in a template?

2011-06-23 Thread Travis Bear


On Jun 23, 1:27 am, Tom Evans  wrote:
> On Thu, Jun 23, 2011 at 8:28 AM, Travis Bear  wrote:
> > Hi,
>
> > I'm using the django.contrib.auth app to manage user login/logout.  I
> > can successfully log in and out, but I cannot access the {{ user }}
> > object in my templates.  If I'm reading these documents correctly,
> > that should be enabled by default:
>
> >    @ zalun
> >    http://stackoverflow.com/questions/41547/always-including-the-user-in...
>
> >  https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-dat...
>
> > Am I missing something?  Here is a snippet from my base.html:
>
> > {% if user.is_authenticated %}
> >    Welcome, {{ user.username }}. Thanks for logging in.
> > {% else %}
> >    Welcome, new user. Please log in.
> > {% endif %}
>
> > If I I have my view explicity include the request.user object in the
> > template context, the above code works as expected.  But I don't want
> > to have to put this in every one of my view functions.
>
> > Here are the template context processors in my settings.py:
>
> > TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
> >                               "django.core.context_processors.debug",
> >                               "django.core.context_processors.i18n",
> >                               "django.core.context_processors.media",
>
> > "django.core.context_processors.request",
> > )
>
> > Any insights appreciated.
>
> 
> You aren't rendering the template with a RequestContext, so
> TEMPLATE_CONTEXT_PROCESSORS doesn't come into play.
> 
>
> Cheers
>
> Tom

I had been under the impression that templates were rendered via the
RequestContext by default.  Specifying this in each of my views did
the trick.  Thanks.


-Travis

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
I'm using django's model inheritance.  Sorry I wasn't clear.  So there's a
Word model and a Verb model.

class Word(models.Model):
# Word stuff

class Verb(Word):
# Verb-specific stuff

The way django handles this is to create a word table and a verb table.  The
verb table has a reference to the word instance in the word table, plus any
other verb-specific information.  I think the database is essentially the
same as this:

class Verb(models.Model):
word = models.ForeignKey('Word')
# Verb-specific stuff

But you're dealing with inheritance in python instead of composition.

On Thu, Jun 23, 2011 at 1:59 PM, Bill Freeman  wrote:

> I'm still confused about what you have (what form of inheritance you are
> using.
>
> In your database, are there both a Word table and a Verb table?  Or is
> there just
> a (set of) Verb (and Noun and Adjective, etc.) table(s), derived from
> a non-Model
> Word class?
>
> If there's a Noun instance "record" and a Verb instance "record", do they
> share
> any data (such that if you change it in one it is changed in the
> other) or do they
> just have duplicate copies of some data?
>
> Bill
>
> On Thu, Jun 23, 2011 at 11:36 AM, Matthew Gardner  wrote:
> > Thanks, Bill, for your comments.
> > Shortly after I posted here I did a little more digging and found this
> > thread from six months ago that described exactly my problem:
> >
> http://groups.google.com/group/django-users/browse_thread/thread/9400999651577bc2/8cc4fe267128d6a3
> > That thread didn't seem to have a good solution, though...
> > As far as whether I should have done inheritance or composition, that's a
> > fair question that could have gone either way.  But I chose inheritance a
> > while ago, as it seemed to make the most sense for what I am doing, and
> > that's the way the code is written.  At several points in my code, I have
> > blocks that do things like this:
> > try:
> > verb = word.verb
> > # do verb-specific stuff
> > except Verb.DoesNotExist:
> > pass
> > I deal with a collection of words most of the time, and if they are also
> > verbs I add some additional stuff.
> > At this point, all I really want to do is add a row to the verb table
> that
> > contains the correct foreign key, without creating a new row in the word
> > table.  And I don't want to write SQL to do it, though if I don't find
> > another solution, that's what I'm going to do, because it's fairly
> > straightforward to just do that.  Also, I want to be able to delete just
> the
> > verb part, which is just deleting the row in the verb table and all
> > corresponding information (i.e., some other tables reference verb but not
> > word, so on deleting the verb row you want to delete the references to
> it).
> > And, now that I look at this, it seems that composition would have
> > simplified those two things, as django makes that nice and easy (with a
> > one-to-one field in Verb).  If I can figure out a nice way to do it while
> > keeping inheritance, it would make my life easier, as I already have a
> bunch
> > of code written and databases that I don't want to repair that use
> > inheritance.  But, given that it looks like composition would probably be
> > easier, maybe I should just take the hit and convert everything?
>  Thoughts?
> > On Thu, Jun 23, 2011 at 10:09 AM, Bill Freeman 
> wrote:
> >>
> >> First, if, despite being related by inheritance, Word and Verb are
> >> separate models, they have separate tables.  Then if you do create
> >> a Verb, the Word still exists, unless you delete it.  Is that what you
> >> want?  If both are to exist, were you hoping that a query for the
> >> same key would still find the Word, or do you want it to find the Verb.
> >> And how do you want to treat words (if text words they are) like
> "record",
> >> which is a noun (keep a record), a verb (record a performance) and an
> >> adjective (record crowd), at the very least.  (Note that the
> pronunciation
> >> of the verb is different, if you were thinking of storing pronunciation
> >> info
> >> in the Word.)
> >>
> >> If you have separate models, you could certainly write the method that
> >> initializes a completely separate sub-class instance from the instance
> >> data of the super class instance.  You could also do some magic using
> >> the field list available in the manager (which has the problem, IIRC,
> that
> >> it is not a public interface) to know which data to copy, though I'm of
> >> the
> >> explicit is better than implicit camp.
> >>
> >> So, I guess that I really don't know enough about your problem to
> >> suggest a detailed technique.  I suspect that if it were me, I'd
> probably
> >> be using a foreign key reference from Verb to Word, rather than
> >> sub-classing.
> >>
> >> Bill
> >>
> >> On Wed, Jun 22, 2011 at 9:45 PM, Matt Gardner 
> wrote:
> >> > Hello all,
> >> >
> >> > I have a model hierarchy in my django app, and there is one very
> >> > important task that I do not know how to do.  I have a bun

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
I'm still confused about what you have (what form of inheritance you are using.

In your database, are there both a Word table and a Verb table?  Or is
there just
a (set of) Verb (and Noun and Adjective, etc.) table(s), derived from
a non-Model
Word class?

If there's a Noun instance "record" and a Verb instance "record", do they share
any data (such that if you change it in one it is changed in the
other) or do they
just have duplicate copies of some data?

Bill

On Thu, Jun 23, 2011 at 11:36 AM, Matthew Gardner  wrote:
> Thanks, Bill, for your comments.
> Shortly after I posted here I did a little more digging and found this
> thread from six months ago that described exactly my problem:
> http://groups.google.com/group/django-users/browse_thread/thread/9400999651577bc2/8cc4fe267128d6a3
> That thread didn't seem to have a good solution, though...
> As far as whether I should have done inheritance or composition, that's a
> fair question that could have gone either way.  But I chose inheritance a
> while ago, as it seemed to make the most sense for what I am doing, and
> that's the way the code is written.  At several points in my code, I have
> blocks that do things like this:
> try:
>     verb = word.verb
>     # do verb-specific stuff
> except Verb.DoesNotExist:
>     pass
> I deal with a collection of words most of the time, and if they are also
> verbs I add some additional stuff.
> At this point, all I really want to do is add a row to the verb table that
> contains the correct foreign key, without creating a new row in the word
> table.  And I don't want to write SQL to do it, though if I don't find
> another solution, that's what I'm going to do, because it's fairly
> straightforward to just do that.  Also, I want to be able to delete just the
> verb part, which is just deleting the row in the verb table and all
> corresponding information (i.e., some other tables reference verb but not
> word, so on deleting the verb row you want to delete the references to it).
> And, now that I look at this, it seems that composition would have
> simplified those two things, as django makes that nice and easy (with a
> one-to-one field in Verb).  If I can figure out a nice way to do it while
> keeping inheritance, it would make my life easier, as I already have a bunch
> of code written and databases that I don't want to repair that use
> inheritance.  But, given that it looks like composition would probably be
> easier, maybe I should just take the hit and convert everything?  Thoughts?
> On Thu, Jun 23, 2011 at 10:09 AM, Bill Freeman  wrote:
>>
>> First, if, despite being related by inheritance, Word and Verb are
>> separate models, they have separate tables.  Then if you do create
>> a Verb, the Word still exists, unless you delete it.  Is that what you
>> want?  If both are to exist, were you hoping that a query for the
>> same key would still find the Word, or do you want it to find the Verb.
>> And how do you want to treat words (if text words they are) like "record",
>> which is a noun (keep a record), a verb (record a performance) and an
>> adjective (record crowd), at the very least.  (Note that the pronunciation
>> of the verb is different, if you were thinking of storing pronunciation
>> info
>> in the Word.)
>>
>> If you have separate models, you could certainly write the method that
>> initializes a completely separate sub-class instance from the instance
>> data of the super class instance.  You could also do some magic using
>> the field list available in the manager (which has the problem, IIRC, that
>> it is not a public interface) to know which data to copy, though I'm of
>> the
>> explicit is better than implicit camp.
>>
>> So, I guess that I really don't know enough about your problem to
>> suggest a detailed technique.  I suspect that if it were me, I'd probably
>> be using a foreign key reference from Verb to Word, rather than
>> sub-classing.
>>
>> Bill
>>
>> On Wed, Jun 22, 2011 at 9:45 PM, Matt Gardner  wrote:
>> > Hello all,
>> >
>> > I have a model hierarchy in my django app, and there is one very
>> > important task that I do not know how to do.  I have a bunch of
>> > instances of the superclass (Word is the model name), and on input
>> > from a user I want to create a subclass instance (Verb) from that
>> > superclass instance.  For example, I might have code like this:
>> >
>>  word = Word.objects.get(pk=[input from user])
>>  verb = Verb.createFromSuperclassInstance(word)
>>  verb.save()
>> >
>> > The only problem is that I know of no such
>> > "createFromSuperclassInstance" method, nor where to look for it.  I do
>> > know how to do this through the database itself (just add a row to the
>> > verb table with the correct foreign key), but I was hoping django
>> > would provide some nice way to do it without me having to explicitly
>> > write SQL.  The Verb class's __init__ method creates a new Word
>> > instance, so that doesn't work, unless there's a way to use it t

Re: manytomany query problem

2011-06-23 Thread Nikhil Somaru
Hi Tony,

Try this:

q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
your_b1_instance
q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with B.B =
your_b2_instance
result = set(q1).intersection(set(q2)) #gives you the A's that are common to
both sets.
result = list(result) #convert it back to a list

There might be an easier way to do it with just the ORM, but that should
work for now

On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:

> You have the question I was asking correct, your notation was fine.
> The only thing I should add is I want to return all A, but filter  my
> "B1"s (as you put it) for each A. I will post my models if need be,
> but they are on another computer and its not convenient right now.  In
> the meantime, do you have any ideas for this query?
>
> On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > It is very hard to read your message. Please format it appropriately next
> > time. Avoid repeating variable names and mixing classes with instances.
> > Could you post your models here?
> >
> > Are you defining the following structure:
> >
> > A hasMany B;
> > B hasMany A;
> > B hasMany B;
> >
> > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.
> >
> >
> >
> > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > I have two models with a manytomany through relation (A and B).  B has
> > > a self referential manytomany relation (a userprofile model).  How
> > > could I filter objects of model B per each relationship with model A?
> > > So lets say 3 arbitrary model A objects have 20 model B object
> > > relations each.  I want to filter the relations so when I return the
> > > filtered version of model A is outputted, each object of type model A
> > > returns only object Bs (the userprofiles) that are connected through
> > > the self referential manytomany relationship to the userprofile (the
> > > object B, sorry if I use them interchangeably but they are the same
> > > thing) that is currently sending in the request.  I figure out which
> > > userprofile is sending the request with a unique identifier sent by
> > > the user in the request (basically their primary key).  Is this type
> > > of filtering possible.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
> >
> > --
> > Yours,
> > Nikhil Somaru
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Yours,
Nikhil Somaru

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



What would be a better views.py code to achieve this particular task .

2011-06-23 Thread Satyajit Sarangi
This is my models.py of a different app .


class PermiLayer(models.Model):
user = models.ForeignKey(User)
table = models.ForeignKey(ContentType)
permi = models.IntegerField()


In another app's views , I am accessing a form that has given me a
username .

I have to check in PermiLayer model if the username along with the
table id match in it and return back the data in permi .

The problem here is , User + table can be present multiple times , as
in the same user and and table id .

What I am doing in my code is , do an object.get.all with a filter of
the username and table id that I have on Permilayer . But ,
object.get.all , as I have read , might just freeze my database , or
slow it down considerably . Is there a faster/better way to do it ?

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



Re: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-06-23 Thread Fatrix
I would like to attend, too.

Thank you in advance!

CU
Fatrix

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



Re: FileField model question

2011-06-23 Thread raj
I actually did google a lot, it's just that every link I got seemed to
show a different way of doing this. I'm going to try that django
snippet way and see where I get. Then I have to figure out how to put
the files up for download after they have been uploaded. Thank you.

On Jun 23, 1:06 pm, Herman Schistad  wrote:
> On Thu, Jun 23, 2011 at 18:51, raj  wrote:
> > I was 
> > readinghttps://docs.djangoproject.com/en/1.3/topics/http/file-uploads/,
> > and I got a little confused when looking at the handle_uploaded_file
> > function.
>
> You should 
> read:https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
>
> And a simple google search on "handle uploaded file django" gives this
> useful snippet:http://djangosnippets.org/snippets/1036/
>
> Did you search google before asking? :-)
>
> --
> With regards, Herman Schistad

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
So, we're talking about "Multi-table inheritance"
(https://docs.djangoproject.com/en/1.3/topics/db/models/#multi-table-inheritance).
 Note that this uses "an automatically-created OneToOneField".

What you really want to do is to create a python instance of the Verb
class.  It's id (in the Verb table) will be empty, meaning the Verb
row will get created on save().  If the field that Verb uses to refer
to Word is already set at save() time, the ORM *MIGHT* just happily
save Verb, and either not save the unmodified Word (I'm pretty sure
that you must have an instantiation of the Word instance lying
around), or, at worst, just update it with unchanged data, rather than
creating a new instance.  You'll have to experiment, unless an ORM
expert speaks up.

One problem is how to set that reference in the Verb object.  I don't
think you get a 'word' attribute on a Verb object, do you?  If worst
comes to worse you can access the attribute by using
v.__dict__['attribute_name'] where v is a Verb instance.  You can poke
around in pdb on a Verb instance that was made and already saved in
the normal way to see how things are named and represented.

You are probably on your own to assure that you don't add more than
one Verb to a given Word.  Some of the reverse lookup stuff may get
confused if there are more than one.  I doubt that the uniqueness
constraint in the DB functions in that direction.  Beware multiple
threads - you may need to play with transactions and roll backs.

And, of course, things could change in a future version even if this works now.

Good luck, Bill

On Thu, Jun 23, 2011 at 2:22 PM, Matthew Gardner  wrote:
> On Thu, Jun 23, 2011 at 2:18 PM, Matthew Gardner  wrote:
>>
>> class Verb(models.Model):
>>     word = models.ForeignKey('Word')
>>     # Verb-specific stuff
>
> Sorry, this is more accurate:
> class Verb(models.Model):
>     word = models.OneToOneField('Word')
>     # verb-specific stuff
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Django password_change

2011-06-23 Thread Mark L.
Hey guys, I'm a newb to Django, but have some experience with Rails.
Its fun to see the similarities and differences in both!

After looking through 
https://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.views
Under the section 'Other built-in views' I think password change is
what I want. I did find this on stackoverflow...

http://stackoverflow.com/questions/388800/django-how-do-i-use-the-built-in-password-reset-change-views-with-my-own-templat

...this focuses on password_reset, but I'm thinking it would apply
also to password_change.

So in my urls.py I added these 2 lines...

(r'^/accounts/password/change/$',
'django.contrib.auth.views.password_change',
{'post_change_redirect' :
'django.contrib.auth.views.password_reset_done'}),


...and I also copied password_change_form.html and
password_change_done.html to /templates/registration/
So after logging in to my system I'm simply trying to go to the /
accounts/password/change/ url. Oh course I'm getting a 404. So I'm not
sure how close I am, but I would appreciate any ideas. Thanx!

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



What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Other than the convenience of writing them, I can't seem to find any
advantages of using model inheritance.

Please allow me to explain the trouble I am having with an example.
Suppose,

class Post(models.Model):
title = models.CharField(max_length=200)
user_owner_id = models.ForeignKey(User)

def __unicode__(self):
return self.title

class BetterPost(Post):
description = models.CharField(max_length=200)

def __unicode__(self):
return self.title

Now, in the template:

{% with profile.user.post_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

{% with profile.user.betterpost_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

If there are 2 'Posts' and 1 'BetterPost', the template code will
print all of the posts in the first loop, then none in the second loop
set.

So why would I use model inheritance if this is the kind of behavior I
can expect? If I can't get a set and can't access the fields, why
wouldn't I just copy the fields into BetterPost rather than extending
Post?

Thank you for reading!
R

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



Best practices to secure admin site

2011-06-23 Thread Phui-Hock
Hi,
This question has been asked a few times, but is there a general set
of best practices one should follow to secure Django admin site? A
quick check on some of the Django powered websites leave /admin/ open
to public access, and some don't even use https for login form
submission.

Although only users marked as staff are allowed to logging to admin
site, but I am not quite comfortable to leave a "backend" site wide
open and take chances. Or am I just being too paranoid?

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



Content type returns this :ContentType matching query does not exist.

2011-06-23 Thread Satyajit Sarangi
My views.py is this
if k == 3:

perm = PermiLayer()
perm.user = user

perm.permi = k
if int(rad4) == 0:
perm.table =
ContentType.objects.get(app_label="OsmMap",model="Osm_Layers")
else :
perm.table =
ContentType.objects.get(app_label="openmaps",model="Open_Layers")

perm.save()
return render_to_response('permgiven.html', {'val':k})


My traceback is this


Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py" in _wrapped_view
  23. return view_func(request, *args, **kwargs)
File "/home/satyajit/geodjango/geographic_admin/permissions/views.py"
in PermLayer
  43.   perm.table =
ContentType.objects.get(app_label="OsmMap",model="Osm_Layers")
File "/usr/local/lib/python2.6/dist-packages/django/db/models/
manager.py" in get
  132. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/
query.py" in get
  349. % self.model._meta.object_name)

Exception Type: DoesNotExist at /permissions/
Exception Value: ContentType matching query does not exist.


what can be the error ?

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



Re: What would be a better views.py code to achieve this particular task .

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]


  
  
You're going to have to explain this a lot better, because I really
did not understand what you mean.

At a *GUESS*, are you trying to prevent against db save race
conditions or something??

Please clarify.

Cal

On 23/06/2011 20:07, Satyajit Sarangi wrote:

  This is my models.py of a different app .


class PermiLayer(models.Model):
user = models.ForeignKey(User)
table = models.ForeignKey(ContentType)
permi = models.IntegerField()


In another app's views , I am accessing a form that has given me a
username .

I have to check in PermiLayer model if the username along with the
table id match in it and return back the data in permi .

The problem here is , User + table can be present multiple times , as
in the same user and and table id .

What I am doing in my code is , do an object.get.all with a filter of
the username and table id that I have on Permilayer . But ,
object.get.all , as I have read , might just freeze my database , or
slow it down considerably . Is there a faster/better way to do it ?




  




-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




Re: What are the advantages of Model inheritance?

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]


  
  
I might be wrong here, but I'm fairly sure that the below example
you pasted is invalid code (i.e. you need to add a proxy _meta??).

My apologies if I'm wrong though, as I have never encountered a need
to do this before, and just going off vague memory.

Cal

On 23/06/2011 19:24, Rich Jones wrote:

  Other than the convenience of writing them, I can't seem to find any
advantages of using model inheritance.

Please allow me to explain the trouble I am having with an example.
Suppose,

class Post(models.Model):
title = models.CharField(max_length=200)
user_owner_id = models.ForeignKey(User)

def __unicode__(self):
return self.title

class BetterPost(Post):
description = models.CharField(max_length=200)

def __unicode__(self):
return self.title

Now, in the template:

{% with profile.user.post_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

{% with profile.user.betterpost_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

If there are 2 'Posts' and 1 'BetterPost', the template code will
print all of the posts in the first loop, then none in the second loop
set.

So why would I use model inheritance if this is the kind of behavior I
can expect? If I can't get a set and can't access the fields, why
wouldn't I just copy the fields into BetterPost rather than extending
Post?

Thank you for reading!
R




  




-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




mach-o, but wrong architecture

2011-06-23 Thread John
O.K.  I know that there are a lot of suggestions out there for this
problem, I think I have tried all of them but I am still getting the
dreaded error in the subject line loading the MySQLdb module.

Everything was working fine, but I was having problems with a
LocMemCache so I decided to upgrade from Django 1.2.3 to Django 1.3.
At the same time I decided to move to Python 2.6 to Python 2.7.  This
is on Mac SnowLeopard on a MacBook Pro.

I have tried build and install of the MySQL-python-1.2.3 connector
using ARCHFLAGS="-arch i386", "-arch -686", "-arch x86-64" and "-arch
x86-32".  I get the same error in all cases.  I can see that the
module being loaded is the one that was built and installed in each
case.

ALso, since it was mentioned as the reason for moving to Django 1.3,
does anyone have any suggestions for solving my cache problem?  I am
trying to save a rather large dictionary of financial calculation
numbers to a LocMemCache.  In the debug environment it works just fine
but when I deploy to an Apache http server the cache seems to get
cleared between each HTTP request.  Via logging I can confirm that the
object is serialized to the cache and can be immediately retrieved
form the cache but the object no longer exists when the next HTTP
request comes in on the same session.

Thank you for your asistance.

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



Re: What would be a better views.py code to achieve this particular task .

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
Please keep your replies on-list so others may benefit in the future.

On Thu, Jun 23, 2011 at 10:01 PM, Satyajit Sarangi <
writetosatya...@gmail.com> wrote:

> First of all , when I am doing this
> perm.table = ContentType.objects.get(app_label="OsmMap",model="Osm_Layers")
> I am getting a content type matching query doesnt exist error .
>

I personally don't ever use the contenttypes framework (at least not
directly), so I can't help you here.


>
> In another app , in its views . I have done this
>
> tab_id = 3
> this_user = request.user
> user1= this_user.pk
> uperm = PermiLayer()
> a=uperm.objects.get(user_id__exact=pk,table_id_exact=tab_id)
> if a.permi == 3:
>lcount = Osm_Layers()
>   lcount= Osm_Layers.objects.get(pk=tab_id)
>   form1 = ReadOnlyForm(initial={"geomcollection": lcount.geom_poly})
>
>
> What I am doing here is this , I am checking if the table_ id and the
> user_id that has logged in has a certain permission . Permission can be any
> number , and thus a certain user on a certain table can have 3 , 2 or/and 1
> as permission . Thus it would repeat itself . Thus , how do I query the db
> better than my present view . And also , what is the query set error?
>

If you are encountering any condition where data is repeating where it
shouldn't, then I'd say there is a fault in your logic.

Also, what do you mean by "what is the query set error"?


>
> On Fri, Jun 24, 2011 at 2:27 AM, Cal Leeming [Simplicity Media Ltd] <
> cal.leem...@simplicitymedialtd.co.uk> wrote:
>
>> **
>> You're going to have to explain this a lot better, because I really did
>> not understand what you mean.
>>
>> At a *GUESS*, are you trying to prevent against db save race conditions or
>> something??
>>
>> Please clarify.
>>
>> Cal
>>
>>
>> On 23/06/2011 20:07, Satyajit Sarangi wrote:
>>
>> This is my models.py of a different app .
>>
>>
>> class PermiLayer(models.Model):
>> user = models.ForeignKey(User)
>> table = models.ForeignKey(ContentType)
>> permi = models.IntegerField()
>>
>>
>> In another app's views , I am accessing a form that has given me a
>> username .
>>
>> I have to check in PermiLayer model if the username along with the
>> table id match in it and return back the data in permi .
>>
>> The problem here is , User + table can be present multiple times , as
>> in the same user and and table id .
>>
>> What I am doing in my code is , do an object.get.all with a filter of
>> the username and table id that I have on Permilayer . But ,
>> object.get.all , as I have read , might just freeze my database , or
>> slow it down considerably . Is there a faster/better way to do it ?
>>
>>
>>
>>
>
>
> --
> *Satyajit Sarangi*
>
>

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



Newbie question, I'm having difficulty getting the admin panel to work!

2011-06-23 Thread Rishi
Hi everyone,
I've just started using Django, and everything has been smooth sailing
up until this part. I added 'django.contrib.admin' in settings.py for
installed apps, and changed urls.py to allow for the admin page to
work. However, the admin page works erratically. That is, at some
points no matter whether I'm at my root project page or at the admin
page, I'll always see that light blue django launch page. At other
times, I get the admin login page to work, but NEVER with any styles
associated with it. It's always just html plaintext. What's going on,
and how do I fix it?

A few specifics about my setup. I'm running django completely remotely
(mediatemple (ve) server), and am using cyberduck/vim concurrently to
edit the files on the server. I'm working on a mac on my side, and I
have doublechecked each configuration file to make sure everything is
saved correctly. I've also installed phpmyadmin and have checked the
database to make sure that's set up correctly. To the best of my
knowledge it is.

Thanks for any and all help!

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



Re: What would be a better views.py code to achieve this particular task .

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
Again, please keep your replies on-list.

I'm afraid I can't help you any further on this, as I don't know enough
about the contenttypes framework, and I still don't really understand what
it is you are asking.

Cal

On Thu, Jun 23, 2011 at 10:07 PM, Satyajit Sarangi <
writetosatya...@gmail.com> wrote:

> I am not saying what is a query set error . I am saying , why am I getting
> such an error , when in the documentation it is mentioned that the exact
> query works .
>
> On Fri, Jun 24, 2011 at 2:35 AM, Cal Leeming [Simplicity Media Ltd] <
> cal.leem...@simplicitymedialtd.co.uk> wrote:
>
>> Please keep your replies on-list so others may benefit in the future.
>>
>> On Thu, Jun 23, 2011 at 10:01 PM, Satyajit Sarangi <
>> writetosatya...@gmail.com> wrote:
>>
>>> First of all , when I am doing this
>>> perm.table =
>>> ContentType.objects.get(app_label="OsmMap",model="Osm_Layers") I am getting
>>> a content type matching query doesnt exist error .
>>>
>>
>> I personally don't ever use the contenttypes framework (at least not
>> directly), so I can't help you here.
>>
>>
>>>
>>> In another app , in its views . I have done this
>>>
>>> tab_id = 3
>>> this_user = request.user
>>> user1= this_user.pk
>>> uperm = PermiLayer()
>>> a=uperm.objects.get(user_id__exact=pk,table_id_exact=tab_id)
>>> if a.permi == 3:
>>>lcount = Osm_Layers()
>>>   lcount= Osm_Layers.objects.get(pk=tab_id)
>>>   form1 = ReadOnlyForm(initial={"geomcollection": lcount.geom_poly})
>>>
>>>
>>> What I am doing here is this , I am checking if the table_ id and the
>>> user_id that has logged in has a certain permission . Permission can be any
>>> number , and thus a certain user on a certain table can have 3 , 2 or/and 1
>>> as permission . Thus it would repeat itself . Thus , how do I query the db
>>> better than my present view . And also , what is the query set error?
>>>
>>
>> If you are encountering any condition where data is repeating where it
>> shouldn't, then I'd say there is a fault in your logic.
>>
>> Also, what do you mean by "what is the query set error"?
>>
>>
>>>
>>> On Fri, Jun 24, 2011 at 2:27 AM, Cal Leeming [Simplicity Media Ltd] <
>>> cal.leem...@simplicitymedialtd.co.uk> wrote:
>>>
 **
 You're going to have to explain this a lot better, because I really did
 not understand what you mean.

 At a *GUESS*, are you trying to prevent against db save race conditions
 or something??

 Please clarify.

 Cal


 On 23/06/2011 20:07, Satyajit Sarangi wrote:

 This is my models.py of a different app .


 class PermiLayer(models.Model):
 user = models.ForeignKey(User)
 table = models.ForeignKey(ContentType)
 permi = models.IntegerField()


 In another app's views , I am accessing a form that has given me a
 username .

 I have to check in PermiLayer model if the username along with the
 table id match in it and return back the data in permi .

 The problem here is , User + table can be present multiple times , as
 in the same user and and table id .

 What I am doing in my code is , do an object.get.all with a filter of
 the username and table id that I have on Permilayer . But ,
 object.get.all , as I have read , might just freeze my database , or
 slow it down considerably . Is there a faster/better way to do it ?




>>>
>>>
>>> --
>>> *Satyajit Sarangi*
>>>
>>>
>>
>
>
> --
> *Satyajit Sarangi*
>
>

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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Where would _meta need to go?

This code does appear to work the way I am describing it, this is just
a slightly stripped down of a real application I have made.

R

On Jun 23, 4:59 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> I might be wrong here, but I'm fairly sure that the below example you pasted 
> is invalid code (i.e. you need to add a proxy _meta??).
> My apologies if I'm wrong though, as I have never encountered a need to do 
> this before, and just going off vague memory.
> Cal
> On 23/06/2011 19:24, Rich Jones wrote:Other than the convenience of writing 
> them, I can't seem to find any advantages of using model inheritance. Please 
> allow me to explain the trouble I am having with an example. Suppose, class 
> Post(models.Model): title = models.CharField(max_length=200) user_owner_id = 
> models.ForeignKey(User) def __unicode__(self): return self.title class 
> BetterPost(Post): description = models.CharField(max_length=200) def 
> __unicode__(self): return self.title Now, in the template: {% with 
> profile.user.post_set.select_related as posts %} {% for post in posts %} 
> {{post}} {% empty %} No posts! {% endfor %} {% endwith %} {% with 
> profile.user.betterpost_set.select_related as posts %} {% for post in posts 
> %} {{post}} {% empty %} No posts! {% endfor %} {% endwith %} If there are 2 
> 'Posts' and 1 'BetterPost', the template code will print all of the posts in 
> the first loop, then none in the second loop set. So why would I use model 
> inheritance if this is the kind of behavior I can expect? If I can't get a 
> set and can't access the fields, why wouldn't I just copy the fields into 
> BetterPost rather than extending Post? Thank you for reading! R

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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
Here you go :)

https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models

On Thu, Jun 23, 2011 at 10:12 PM, Rich Jones  wrote:

> Where would _meta need to go?
>
> This code does appear to work the way I am describing it, this is just
> a slightly stripped down of a real application I have made.
>
> R
>
> On Jun 23, 4:59 pm, "Cal Leeming [Simplicity Media Ltd]"
>  wrote:
> > I might be wrong here, but I'm fairly sure that the below example you
> pasted is invalid code (i.e. you need to add a proxy _meta??).
> > My apologies if I'm wrong though, as I have never encountered a need to
> do this before, and just going off vague memory.
> > Cal
> > On 23/06/2011 19:24, Rich Jones wrote:Other than the convenience of
> writing them, I can't seem to find any advantages of using model
> inheritance. Please allow me to explain the trouble I am having with an
> example. Suppose, class Post(models.Model): title =
> models.CharField(max_length=200) user_owner_id = models.ForeignKey(User) def
> __unicode__(self): return self.title class BetterPost(Post): description =
> models.CharField(max_length=200) def __unicode__(self): return self.title
> Now, in the template: {% with profile.user.post_set.select_related as posts
> %} {% for post in posts %} {{post}} {% empty %} No posts! {% endfor %} {%
> endwith %} {% with profile.user.betterpost_set.select_related as posts %} {%
> for post in posts %} {{post}} {% empty %} No posts! {% endfor %} {% endwith
> %} If there are 2 'Posts' and 1 'BetterPost', the template code will print
> all of the posts in the first loop, then none in the second loop set. So why
> would I use model inheritance if this is the kind of behavior I can expect?
> If I can't get a set and can't access the fields, why wouldn't I just copy
> the fields into BetterPost rather than extending Post? Thank you for
> reading! R
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Inconsistent keyword filtering on FK

2011-06-23 Thread EAMiller
I'm getting a 'cannot resolve keyword' on a objects.filter that
doesn't seem to make sense.

Here is the model:

class Person(models.Model):
payee = models.ForeignKey(
Payee,
null=True,
blank=True,
)
ut = models.ForeignKey(
Utility,
null=True,
blank=True,
)

The problem:

Utility.objects.filter(person=1144) # works fine
Payee.objects.filter(person=26) # gives us FieldError: Cannot resolve
keyword 'person' into field

I've tried to follow this around, finding myself in the Options object
where I printed out self._related_objects_cache.items() ... Utility
has about 20 other models that define a FK to it, and appear in the
related objects cache. Payee has about 13 models that define a FK to
it - but only one of them appears in the related object cache (and
it's not 'person')

I haven't been able to track it beyond this point to anything
conclusive. Any suggestions on where to look next?

using: django 1.3 (had same issue in 1.1 before migrating), postgres
8.4 / psycopg2

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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread bruno desthuilliers
On Jun 23, 8:24 pm, Rich Jones  wrote:
> Other than the convenience of writing them, I can't seem to find any
> advantages of using model inheritance.

Really ???


> Please allow me to explain the trouble I am having with an example.
> Suppose,
>
> class Post(models.Model):
>     title = models.CharField(max_length=200)
>     user_owner_id = models.ForeignKey(User)
>
>     def __unicode__(self):
>         return self.title
>
> class BetterPost(Post):
>     description = models.CharField(max_length=200)
>
>     def __unicode__(self):
>         return self.title

You don't need to redifine __unicode__ here.

> Now, in the template:
>
> {% with profile.user.post_set.select_related as posts %}

For what you're doing in the template and given your models, the
select_related is totally useless.

>     {% for post in posts %}
>         {{post}}
>     {% empty %}
>         No posts!
>     {% endfor %}
> {% endwith %}
>
> {% with profile.user.betterpost_set.select_related as posts %}
>     {% for post in posts %}
>         {{post}}
>     {% empty %}
>         No posts!
>     {% endfor %}
> {% endwith %}
>
> If there are 2 'Posts' and 1 'BetterPost',

Belonging to the same user ???

> the template code will
> print all of the posts in the first loop, then none in the second loop
> set.

If so, please inspect your data, as there's obviously something wrong.
With your data, I mean.

> So why would I use model inheritance if this is the kind of behavior I
> can expect? If I can't get a set and can't access the fields, why
> wouldn't I just copy the fields into BetterPost rather than extending
> Post?

If that was the case, then model inheritance would indeed be a plain
waste of time. Now, just a simple question: do you really think anyone
would have wasted time implementing model inheritance, testing it, and
documenting it if that was all you could "expect" from it ?

FWIW, I have been using model inheritance - abstract and concrete - in
half a dozen projects, with about 30 model subclasses in one of them,
and it JustWorks(tm).

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



Re: Inconsistent keyword filtering on FK

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
On Thu, Jun 23, 2011 at 10:16 PM, EAMiller  wrote:

> I'm getting a 'cannot resolve keyword' on a objects.filter that
> doesn't seem to make sense.
>
> Here is the model:
>
> class Person(models.Model):
>payee = models.ForeignKey(
>Payee,
>null=True,
>blank=True,
>)
>ut = models.ForeignKey(
>Utility,
>null=True,
>blank=True,
>)
>
> The problem:
>
> Utility.objects.filter(person=1144) # works fine
> Payee.objects.filter(person=26) # gives us FieldError: Cannot resolve
> keyword 'person' into field
>

Is this what you need??

Payee.objects.filter(
person = Person(id=26)
)

or.. Payee.objects.filter(
person__id = 26
) - but this would be slightly more performance hitting i think.



>
> I've tried to follow this around, finding myself in the Options object
> where I printed out self._related_objects_cache.items() ... Utility
> has about 20 other models that define a FK to it, and appear in the
> related objects cache. Payee has about 13 models that define a FK to
> it - but only one of them appears in the related object cache (and
> it's not 'person')
>
> I haven't been able to track it beyond this point to anything
> conclusive. Any suggestions on where to look next?
>
> using: django 1.3 (had same issue in 1.1 before migrating), postgres
> 8.4 / psycopg2
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Inconsistent keyword filtering on FK

2011-06-23 Thread Ian Clelland
On Thu, Jun 23, 2011 at 2:21 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> The problem:
>>
>> Utility.objects.filter(person=1144) # works fine
>> Payee.objects.filter(person=26) # gives us FieldError: Cannot resolve
>> keyword 'person' into field
>>
>
> Is this what you need??
>
> Payee.objects.filter(
> person = Person(id=26)
> )
>
> or.. Payee.objects.filter(
> person__id = 26
> ) - but this would be slightly more performance hitting i think.
>

or just

Payee.objects.filter(person_id=26)

person__id is a field lookup on the person model, so (in theory) Django will
contruct the SQL join, and test the person.id column. person_id is a column
in the payee table, and Django will construct SQL which compares against
that.

I don't know if there's any practical difference in performance -- I would
hope that any decent SQL query optimizer should be able to change

select payee.* from payee join person on (payee.person_id = person.id) where
person.id = 26

into

select payee.* from payee where person_id = 26


-- 
Regards,
Ian Clelland


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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread Micky Hulse
On Thu, Jun 23, 2011 at 2:17 PM, bruno desthuilliers
 wrote:
> FWIW, I have been using model inheritance - abstract and concrete - in
> half a dozen projects, with about 30 model subclasses in one of them,
> and it JustWorks(tm).

That sounds pretty sweet! :D

I would love to see some examples.

I have been using abstract models for some of my projects... I find
them extremely useful:

https://gist.github.com/1043698

It works for me... Of course, I am still a noobie to Python/Django, so
may the feedback be kind. :: crosses fingers :: :D

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



Re: Inconsistent keyword filtering on FK

2011-06-23 Thread Ethan Miller

On Jun 23, 2011, at 2:21 PM, Cal Leeming [Simplicity Media Ltd] wrote:

> Payee.objects.filter(
> person = Person(id=26)
> )
> 
> or.. Payee.objects.filter(
> person__id = 26
> ) 

Both of these return the same error - it lists out all the "choices" which are 
all fields on the payee table itself (and the one I mentioned that appears in 
the cache)

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



Re: Inconsistent keyword filtering on FK

2011-06-23 Thread Ethan Miller

On Jun 23, 2011, at 2:30 PM, Ian Clelland wrote:

> person_id is a column in the payee table, and Django will construct SQL which 
> compares against that.

It's the reverse actually payee_id is a column on the person table so I 
guess the resulting SQL would need to be 

select * from er_payee, er_person where er_person.id = 26 and 
er_person.payee_id = er_payee.id;

or

select * from er_payee join er_person on er_person.id = 26 and 
er_person.payee_id = er_payee.id;

? In any case it's not getting that far - seems like it fails before it even 
builds a query ...

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



Re: mach-o, but wrong architecture

2011-06-23 Thread Andy Dustman
Did you make sure you completely cleaned out the build directory
between attempts? I.e. manually remove it. Also see (if you haven't
already) 
http://stackoverflow.com/questions/3061277/python-mysql-wrong-architecture-error

I don't know exactly why it's so hard to build on Mac OS X, and I
wrote the package... I do know the MacPorts route works, because
that's why I'm using. The only thing MacPorts seems to do is change
the name of mysql_config to mysql_config5 (because of the way they do
MySQL package versioning). But with MacPorts, you end up building
MySQL itself for your architecture, rather than the fat binary
packages which mysql.com provides.

On Thu, Jun 23, 2011 at 5:00 PM, John  wrote:
> O.K.  I know that there are a lot of suggestions out there for this
> problem, I think I have tried all of them but I am still getting the
> dreaded error in the subject line loading the MySQLdb module.
>
> Everything was working fine, but I was having problems with a
> LocMemCache so I decided to upgrade from Django 1.2.3 to Django 1.3.
> At the same time I decided to move to Python 2.6 to Python 2.7.  This
> is on Mac SnowLeopard on a MacBook Pro.
>
> I have tried build and install of the MySQL-python-1.2.3 connector
> using ARCHFLAGS="-arch i386", "-arch -686", "-arch x86-64" and "-arch
> x86-32".  I get the same error in all cases.  I can see that the
> module being loaded is the one that was built and installed in each
> case.
>
> ALso, since it was mentioned as the reason for moving to Django 1.3,
> does anyone have any suggestions for solving my cache problem?  I am
> trying to save a rather large dictionary of financial calculation
> numbers to a LocMemCache.  In the debug environment it works just fine
> but when I deploy to an Apache http server the cache seems to get
> cleared between each HTTP request.  Via logging I can confirm that the
> object is serialized to the cache and can be immediately retrieved
> form the cache but the object no longer exists when the next HTTP
> request comes in on the same session.
>
> Thank you for your asistance.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Question the answers

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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Even ignoring the select_related then - the fact is that

user.post_set works and user.betterpost_set won't work, seemingly as
the result of using model inheritance.

Perhaps I could get all of the posts (post and betterposts) and then
filter by time? Does that make sense / is there a way to do that in
the template?

R

On Jun 23, 5:40 pm, Micky Hulse  wrote:
> On Thu, Jun 23, 2011 at 2:17 PM, bruno desthuilliers
>
>  wrote:
> > FWIW, I have been using model inheritance - abstract and concrete - in
> > half a dozen projects, with about 30 model subclasses in one of them,
> > and it JustWorks(tm).
>
> That sounds pretty sweet! :D
>
> I would love to see some examples.
>
> I have been using abstract models for some of my projects... I find
> them extremely useful:
>
> https://gist.github.com/1043698
>
> It works for me... Of course, I am still a noobie to Python/Django, so
> may the feedback be kind. :: crosses fingers :: :D

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



Re: Best practices to secure admin site

2011-06-23 Thread Jacob Kaplan-Moss
On Thu, Jun 23, 2011 at 3:33 PM, Phui-Hock  wrote:
> This question has been asked a few times, but is there a general set
> of best practices one should follow to secure Django admin site? A
> quick check on some of the Django powered websites leave /admin/ open
> to public access, and some don't even use https for login form
> submission.
>
> Although only users marked as staff are allowed to logging to admin
> site, but I am not quite comfortable to leave a "backend" site wide
> open and take chances. Or am I just being too paranoid?

There are no known vulnerabilities in the admin's auth code, but "no
known vulnerabilities" is a long way from "no vulnerabilities full
stop". I trust Django pretty far, but I don't think it's paranoia to
add a few other layers of security on top. I generally do the
following:

* Only allow HTTPS (to the admin, and perhaps to the entire site).
* Don't use "/admin/" -- I usually use a separate subdomain like
"backend.example.com", or sometimes just a different root (I often see
"nqzva" -- figuring out why is left as an exercise for the reader :).
* Limit access based on IP, when appropriate -- many corporate
settings will already have a VPN, for example, so piggyback on that if
possible.

Of the three, I consider SSL non-negotiable: there's no good reason to
allow insecure connections to the admin.

Jacob

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



Re: What would be a better views.py code to achieve this particular task .

2011-06-23 Thread Satyajit Sarangi
I'm afraid I can't help you any further on this, as I don't know enough
about the contenttypes framework, and I still don't really understand what
it is you are asking.

Cal



I got it fixed . Now I have smaller issue . Foreign key ( of a particular
model) is returning me a table_id with some random integer value . How do I
use that to actually access the table .

As in , in another app , how do I know an integer 34 refers to a particular
row of the table from which the foreign key has been taken

Satyajit
On Fri, Jun 24, 2011 at 2:40 AM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Again, please keep your replies on-list.
>
> I'm afraid I can't help you any further on this, as I don't know enough
> about the contenttypes framework, and I still don't really understand what
> it is you are asking.
>
> Cal
>
>
> On Thu, Jun 23, 2011 at 10:07 PM, Satyajit Sarangi <
> writetosatya...@gmail.com> wrote:
>
>> I am not saying what is a query set error . I am saying , why am I getting
>> such an error , when in the documentation it is mentioned that the exact
>> query works .
>>
>> On Fri, Jun 24, 2011 at 2:35 AM, Cal Leeming [Simplicity Media Ltd] <
>> cal.leem...@simplicitymedialtd.co.uk> wrote:
>>
>>> Please keep your replies on-list so others may benefit in the future.
>>>
>>> On Thu, Jun 23, 2011 at 10:01 PM, Satyajit Sarangi <
>>> writetosatya...@gmail.com> wrote:
>>>
 First of all , when I am doing this
 perm.table =
 ContentType.objects.get(app_label="OsmMap",model="Osm_Layers") I am getting
 a content type matching query doesnt exist error .

>>>
>>> I personally don't ever use the contenttypes framework (at least not
>>> directly), so I can't help you here.
>>>
>>>

 In another app , in its views . I have done this

 tab_id = 3
 this_user = request.user
 user1= this_user.pk
 uperm = PermiLayer()
 a=uperm.objects.get(user_id__exact=pk,table_id_exact=tab_id)
 if a.permi == 3:
lcount = Osm_Layers()
   lcount= Osm_Layers.objects.get(pk=tab_id)
   form1 = ReadOnlyForm(initial={"geomcollection":
 lcount.geom_poly})


 What I am doing here is this , I am checking if the table_ id and the
 user_id that has logged in has a certain permission . Permission can be any
 number , and thus a certain user on a certain table can have 3 , 2 or/and 1
 as permission . Thus it would repeat itself . Thus , how do I query the db
 better than my present view . And also , what is the query set error?

>>>
>>> If you are encountering any condition where data is repeating where it
>>> shouldn't, then I'd say there is a fault in your logic.
>>>
>>> Also, what do you mean by "what is the query set error"?
>>>
>>>

 On Fri, Jun 24, 2011 at 2:27 AM, Cal Leeming [Simplicity Media Ltd] <
 cal.leem...@simplicitymedialtd.co.uk> wrote:

> **
> You're going to have to explain this a lot better, because I really did
> not understand what you mean.
>
> At a *GUESS*, are you trying to prevent against db save race conditions
> or something??
>
> Please clarify.
>
> Cal
>
>
> On 23/06/2011 20:07, Satyajit Sarangi wrote:
>
> This is my models.py of a different app .
>
>
> class PermiLayer(models.Model):
> user = models.ForeignKey(User)
> table = models.ForeignKey(ContentType)
> permi = models.IntegerField()
>
>
> In another app's views , I am accessing a form that has given me a
> username .
>
> I have to check in PermiLayer model if the username along with the
> table id match in it and return back the data in permi .
>
> The problem here is , User + table can be present multiple times , as
> in the same user and and table id .
>
> What I am doing in my code is , do an object.get.all with a filter of
> the username and table id that I have on Permilayer . But ,
> object.get.all , as I have read , might just freeze my database , or
> slow it down considerably . Is there a faster/better way to do it ?
>
>
>
>


 --
 *Satyajit Sarangi*


>>>
>>
>>
>> --
>> *Satyajit Sarangi*
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
*Satyajit Sarangi*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this g

How to use the foreign key to get the exact row of that particular table ?

2011-06-23 Thread Satyajit Sarangi
My models.py is this

class PermiLayer(models.Model):
user = models.ForeignKey(User)
table = models.ForeignKey(ContentType)
permi = models.IntegerField()

My views.py is this

perm.table =
ContentType.objects.get(app_label="OsmMap",model="osmlayers")

Perm.table is storing an integer . How do I use that integer , and get
a row of osmlayers ?

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



Re: mach-o, but wrong architecture

2011-06-23 Thread Malcolm Box
Re your cacheing problem the behaviour you are seeing is exactly what would be 
expected using locmem cache. 

Apache is presumably running multiple processes each of which will have it's 
own locmem cache. Since the odds ate against two successive requests hitting 
the same apache process, you won't see the data in your cache. 

The simplest fix is to use memcached. 

HTH
Malcolm

Sent from my iPhone, please excuse any typos

On 23 Jun 2011, at 22:00, John  wrote:

> O.K.  I know that there are a lot of suggestions out there for this
> problem, I think I have tried all of them but I am still getting the
> dreaded error in the subject line loading the MySQLdb module.
> 
> Everything was working fine, but I was having problems with a
> LocMemCache so I decided to upgrade from Django 1.2.3 to Django 1.3.
> At the same time I decided to move to Python 2.6 to Python 2.7.  This
> is on Mac SnowLeopard on a MacBook Pro.
> 
> I have tried build and install of the MySQL-python-1.2.3 connector
> using ARCHFLAGS="-arch i386", "-arch -686", "-arch x86-64" and "-arch
> x86-32".  I get the same error in all cases.  I can see that the
> module being loaded is the one that was built and installed in each
> case.
> 
> ALso, since it was mentioned as the reason for moving to Django 1.3,
> does anyone have any suggestions for solving my cache problem?  I am
> trying to save a rather large dictionary of financial calculation
> numbers to a LocMemCache.  In the debug environment it works just fine
> but when I deploy to an Apache http server the cache seems to get
> cleared between each HTTP request.  Via logging I can confirm that the
> object is serialized to the cache and can be immediately retrieved
> form the cache but the object no longer exists when the next HTTP
> request comes in on the same session.
> 
> Thank you for your asistance.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Thomas Weholt
For the impatient:

http://pypi.python.org/pypi/dse/3.0.0.Beta-1
Source at https://bitbucket.org/weholt/dse2/src
Modified BSD license.

New in the 3.x version of DSE is the bulk_update-method, more
intuitive syntax and code clean up.
NB! The new syntax is not backwards compatible so existing code using
DSE must be updated to work.

New syntax:

with Person.delayed as d:
d.insert({'name': 'Thomas', 'age': 36, 'sex': 'M'})
d.update({'id': 1, 'name': 'John'})
d.delete(10) # Deletes record with id 10

I hope the syntax is more intuitive and easy to read. Comments wanted.

Bulk update It takes a dictionary of values to update, requires a
value for the primary key/id of the record, but uses the django orm's
own update method
instead of plain sql to reduce number of statements to execute. This
is helpful when your fields can have a limited set of values, like
EXIF-data from photos or metadata from mp3s.

An example::

with Photo.delayed as d:
d.update({'id': 1, 'camera_model': 'Nikon', 'fnumber': 2.8,
'iso_speed': 200})
d.update({'id': 2, 'camera_model': 'Nikon', 'fnumber': 11,
'iso_speed': 400})
d.update({'id': 3, 'camera_model': 'Nikon', 'fnumber': 2.8,
'iso_speed': 400})
d.update({'id': 4, 'camera_model': 'Canon', 'fnumber': 3.5,
'iso_speed': 200})
d.update({'id': 5, 'camera_model': 'Canon', 'fnumber': 11,
'iso_speed': 800})
d.update({'id': 6, 'camera_model': 'Pentax', 'fnumber': 11,
'iso_speed': 800})
d.update({'id': 7, 'camera_model': 'Sony', 'fnumber': 3.5,
'iso_speed': 1600})
# and then some thousand more lines like that

Internally DSE will construct a structure like this::

bulk_updates = {
'camera_model': {
'Nikon': [1,2,3],
'Canon': [4,5],
'Pentax': [6],
'Sony': [7],
},
'fnumber': {
2.8: [1,3],
11: [2,5,6],
3.5: [4,7],
},
'iso_speed': {
200: [1,4],
400: [2,3],
800: [5,6],
1600: [7]
}
}

And then execute those statements using::

# pk = the primary key field for the model, in most cases id
for field, values in bulk_updates.iteritems():
for value, ids in values.iteritems():
model.objects.filter(**{"%s__in" % pk:
ids}).update(**{field: value})

For huge datasets where the fields can have limited values this has a
big impact on performance. So when to use
update or bulk_update depends on the data you want to process. For
instance importing a contact list where most
of the fields had almost unique values would benefit from the
update-method, but importing data from photos, id3-tags
from your music collection etc would process much faster using bulk_update.

Thanks to Cal Leeming [Simplicity Media Ltd] for inspiration on this one :-)

-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

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



Re: Newbie question, I'm having difficulty getting the admin panel to work!

2011-06-23 Thread Eiji Kobayashi
Hello,

I'm not exactly sure about your other problems, but the problem with not
getting any styles seem to me like you didn't set your ADMIN_MEDIA_PREFIX
correctly in your settings file and/or your web server configuration file.
You must let it know how to access all the javascript, css and image files
to display your admin pages correctly.

I'm not sure what type web server mediatemple uses, but I am using nginx
(under Debian stable) and I had to put this in my server configuration file:

server {
...
location ^~ /static/admin/ {
  alias /usr/lib/python2.5/sites-packages/django/contrib/admin/media/;
}
location ^~ /static/ {
  root /var/www;
}
...

For apache, I believe an equivalent setting would be something like this in
your virtualhost file:
...
Alias /static/admin/
"/usr/lib/python2.5/sites-packages/django/contrib/admin/media"
...

And in the settings.py file of my project, I set the following:
...
STATIC_URL = '/var/www/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'

This tells Django to issue the '/static/admin/' prefix whenever it needs
something to display the admin pages, and then the webserver will follow up
by retrieving them from the correct place
(/path/to/python/site-packages/django/contrib/admin/media).

I hope this works. Good luck!

Eiji

P.S. What erratic behaviors are you seeing? Please explain more.

On Thu, Jun 23, 2011 at 1:25 PM, Rishi  wrote:

> Hi everyone,
> I've just started using Django, and everything has been smooth sailing
> up until this part. I added 'django.contrib.admin' in settings.py for
> installed apps, and changed urls.py to allow for the admin page to
> work. However, the admin page works erratically. That is, at some
> points no matter whether I'm at my root project page or at the admin
> page, I'll always see that light blue django launch page. At other
> times, I get the admin login page to work, but NEVER with any styles
> associated with it. It's always just html plaintext. What's going on,
> and how do I fix it?
>
> A few specifics about my setup. I'm running django completely remotely
> (mediatemple (ve) server), and am using cyberduck/vim concurrently to
> edit the files on the server. I'm working on a mac on my side, and I
> have doublechecked each configuration file to make sure everything is
> saved correctly. I've also installed phpmyadmin and have checked the
> database to make sure that's set up correctly. To the best of my
> knowledge it is.
>
> Thanks for any and all help!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Custom form on formset does not use Meta 'widgets', bug?

2011-06-23 Thread adrian
Django dev, Python 2.6.6

Just wondering if I should file a bug report or am I just doing
something wrong.

I have an inline:


class ProductImageInline(admin.StackedInline):
model = ProductImage
formset = ProductImageFormset


...the form declaration and formset factory call:


class ProductImageForm(forms.ModelForm):

class Meta:
model = ProductImage
widgets = {
'picture': AdminImageJCropWidget(auto_enable=True,
jcrop_options=JCROP_OPTIONS)
}

ProductImageFormset = inlineformset_factory(Product, ProductImage,
form=ProductImageForm,
 
formset=BaseJCropImageFormset, extra=3)


The widgets declaration on the Meta class is not sticking. Bug?


However, if I add a formfield_overrides to my inline, it works:

class NewProductImageInline(admin.StackedInline):
model = ProductImage
formset = ProductImageFormset

formfield_overrides = {
models.ImageField: {'widget':
AdminImageJCropWidget(auto_enable=True, jcrop_options=JCROP_OPTIONS)},
}


The former looks like it should work and I prefer it over the latter
method, can anyone shed some light on this for me?

Thanks.

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



Re: Django password_change

2011-06-23 Thread Eiji Kobayashi
Hi,

Maybe you made a mistake, but your url says /account/password/change, but
you put the password*.html files to /templates/registration. Shouldn't it be
inside your project's templates/account directory? Maybe that is why you're
getting a 404?

Just a guess

Eiji

On Thu, Jun 23, 2011 at 11:53 AM, Mark L.  wrote:

> Hey guys, I'm a newb to Django, but have some experience with Rails.
> Its fun to see the similarities and differences in both!
>
> After looking through
> https://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.views
> Under the section 'Other built-in views' I think password change is
> what I want. I did find this on stackoverflow...
>
>
> http://stackoverflow.com/questions/388800/django-how-do-i-use-the-built-in-password-reset-change-views-with-my-own-templat
>
> ...this focuses on password_reset, but I'm thinking it would apply
> also to password_change.
>
> So in my urls.py I added these 2 lines...
>
> (r'^/accounts/password/change/$',
> 'django.contrib.auth.views.password_change',
>{'post_change_redirect' :
> 'django.contrib.auth.views.password_reset_done'}),
>
>
> ...and I also copied password_change_form.html and
> password_change_done.html to /templates/registration/
> So after logging in to my system I'm simply trying to go to the /
> accounts/password/change/ url. Oh course I'm getting a 404. So I'm not
> sure how close I am, but I would appreciate any ideas. Thanx!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 12:49 AM, Cal Leeming [Simplicity Media Ltd]
 wrote:
>
>
> On Thu, Jun 23, 2011 at 5:46 PM, Shawn Milochik  wrote:
>>
>> On 06/23/2011 12:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:
>>>
>>> The perfect link to refer these users to:
>>>
>>> http://www.catb.org/~esr/faqs/smart-questions.html
>>> 
>>>
>>> (props to harryr for finding this)
>>>
>>
>> Yeah. I used to post that link pretty frequently until I was asked to
>> stop. ;o)
>
> Lmao, I won't re-post this again then ;p
>
>>
>> I still think it's a great essay. If I remember correctly, the objection
>> to it was that the tone wasn't necessarily at the same level of acceptance
>> and friendliness we like to maintain in this group.
>>
>> We should distill it into a shorter, newbie-friendly version and get it
>> posted somewhere official so we can refer to it.
>
> That's be pretty cool. But my guess is that the maintainers just want us to
> reply with a "you need to give us more information before we can help you"
> speech, in a non-insulting tone. Shame, takes all the fun out of it lol.
> 

The tone is exactly why I've asked people to stop referring to ESR's
document. The spirit of the document -- that you can only get good
answers if you ask good questions -- is certainly valid, but to me,
ESR's tone in that document really comes off as "Stop wasting my time,
which is more valuable than yours, because I'm a hacker, which means
I'm awesome and you're not". I'm sorry, but being a 1337 h4X0R doesn't
give you carte blanche to treat anyone else like crap.

The Django core team have tried really hard to foster a positive,
accepting community culture. Everyone is a beginner once, and everyone
occasionally posts in haste and forgets to include salient details.
Absolutely nothing is gained by insulting a newcomer to the community.

As a side note, if someone were to redraft that document in such a way
that it *doesn't* have that tone, I'd gladly include the text in
Django's own documentation.

Yours,
Russ Magee %-)

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



Re: manytomany query problem

2011-06-23 Thread Tony
Nikhil,
This email will be significantly shorter than the one I wrote 5
minutes ago before my laptop ran out of battery and failed to get
sent.  I didn't explain this clearly so I am going to give an example
(a much smaller one than the one I jsut wrote).
Lets say I have 3 object As (a1, a2, a3) and 3 object Bs (b1, b2, b3).
the relations are as follows:
a1 to (b1, b2), a2 to (b2, b3), a3 to (b1, b3)
The user who makes the request is b2. b2 has a "friend connection"
with b1 only (so b2 to (b1,)).  It could have more friends, but for
simplicity it will have only 1.  What I want to return is this:
a1 to (b1,), a2 to None, a3 to (b1,).

I always want to return all of my model "A" objects, but I want to
filter the model "B" objects within each based on who the current
user's "friend connections are".  How do I do this in code?

On Jun 23, 9:02 pm, Nikhil Somaru  wrote:
> Hi Tony,
>
> Try this:
>
> q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
> your_b1_instance
> q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with B.B =
> your_b2_instance
> result = set(q1).intersection(set(q2)) #gives you the A's that are common to
> both sets.
> result = list(result) #convert it back to a list
>
> There might be an easier way to do it with just the ORM, but that should
> work for now
>
>
>
>
>
>
>
>
>
> On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:
> > You have the question I was asking correct, your notation was fine.
> > The only thing I should add is I want to return all A, but filter  my
> > "B1"s (as you put it) for each A. I will post my models if need be,
> > but they are on another computer and its not convenient right now.  In
> > the meantime, do you have any ideas for this query?
>
> > On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > > It is very hard to read your message. Please format it appropriately next
> > > time. Avoid repeating variable names and mixing classes with instances.
> > > Could you post your models here?
>
> > > Are you defining the following structure:
>
> > > A hasMany B;
> > > B hasMany A;
> > > B hasMany B;
>
> > > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.
>
> > > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > > I have two models with a manytomany through relation (A and B).  B has
> > > > a self referential manytomany relation (a userprofile model).  How
> > > > could I filter objects of model B per each relationship with model A?
> > > > So lets say 3 arbitrary model A objects have 20 model B object
> > > > relations each.  I want to filter the relations so when I return the
> > > > filtered version of model A is outputted, each object of type model A
> > > > returns only object Bs (the userprofiles) that are connected through
> > > > the self referential manytomany relationship to the userprofile (the
> > > > object B, sorry if I use them interchangeably but they are the same
> > > > thing) that is currently sending in the request.  I figure out which
> > > > userprofile is sending the request with a unique identifier sent by
> > > > the user in the request (basically their primary key).  Is this type
> > > > of filtering possible.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-users@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > Yours,
> > > Nikhil Somaru
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Yours,
> Nikhil Somaru

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



How do I add this particular url in my template ?

2011-06-23 Thread Satyajit Sarangi
This is the url http://127.0.0.1:8000/admin/maps/test/  .

When I click on a link on a particular template , it should take me
there . How do I manage it ?
The reason why I am asking is this is in the admin .

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



Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
Thanks for your input, Bill, I appreciate it.  I think I'm just going to
take a hit and switch to an explicit OneToOneField instead of trying to make
this work with inheritance.  The other way things will just work, because
django's built to make it work, but doing it with inheritance is difficult
and ugly.  Thanks for helping me see that.  I wonder if it's worth putting a
note in the django docs that in some cases a OneToOneField is more
appropriate than inheritance, given some of these problems (and the fact
that other people have had the same problem, as I noted with my link to a
previous post to django-users).  Anyway, thanks again for your help.

Matt

On Thu, Jun 23, 2011 at 3:47 PM, Bill Freeman  wrote:

> So, we're talking about "Multi-table inheritance"
> (
> https://docs.djangoproject.com/en/1.3/topics/db/models/#multi-table-inheritance
> ).
>  Note that this uses "an automatically-created OneToOneField".
>
> What you really want to do is to create a python instance of the Verb
> class.  It's id (in the Verb table) will be empty, meaning the Verb
> row will get created on save().  If the field that Verb uses to refer
> to Word is already set at save() time, the ORM *MIGHT* just happily
> save Verb, and either not save the unmodified Word (I'm pretty sure
> that you must have an instantiation of the Word instance lying
> around), or, at worst, just update it with unchanged data, rather than
> creating a new instance.  You'll have to experiment, unless an ORM
> expert speaks up.
>
> One problem is how to set that reference in the Verb object.  I don't
> think you get a 'word' attribute on a Verb object, do you?  If worst
> comes to worse you can access the attribute by using
> v.__dict__['attribute_name'] where v is a Verb instance.  You can poke
> around in pdb on a Verb instance that was made and already saved in
> the normal way to see how things are named and represented.
>
> You are probably on your own to assure that you don't add more than
> one Verb to a given Word.  Some of the reverse lookup stuff may get
> confused if there are more than one.  I doubt that the uniqueness
> constraint in the DB functions in that direction.  Beware multiple
> threads - you may need to play with transactions and roll backs.
>
> And, of course, things could change in a future version even if this works
> now.
>
> Good luck, Bill
>
> On Thu, Jun 23, 2011 at 2:22 PM, Matthew Gardner  wrote:
> > On Thu, Jun 23, 2011 at 2:18 PM, Matthew Gardner  wrote:
> >>
> >> class Verb(models.Model):
> >> word = models.ForeignKey('Word')
> >> # Verb-specific stuff
> >
> > Sorry, this is more accurate:
> > class Verb(models.Model):
> > word = models.OneToOneField('Word')
> > # verb-specific stuff
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: What are the advantages of Model inheritance?

2011-06-23 Thread Matthew Gardner
I think you're right, Rich, that when you query on a table, it'll only grab
the results for that table.  So when you do user.post_set.all(), it only
creates Post objects, because it only pulls data from that one table.  When
you do user.betterpost_set.all(), the reason you don't see anything is that
that line of code raises an error, because user doesn't have a
"betterpost_set" attribute.  The templating language hides the error for
you, so you just get no output.

So, yeah, if you want real polymorphic inheritance, you aren't going to get
it with django, as far as I know.  And in that regard, you're probably
better off not using inheritance so that you won't expect those kinds of
features.  Abstract inheritance has its benefits in code simplification, and
I can imagine that multi-table inheritance also has some uses, but they are
not the ones that you typically expect from inheritance in python.

In case you aren't aware, to actually get at the subclass instance from a
superclass instance in django, you have to do something like this:

try:
bp = post.betterpost
# do stuff with bp
except BetterPost.DoesNotExist:
pass

To get the behavior you want in that template, you need to manually create
the list of posts in the python code, doing something like the following:

posts_queryset = user.post_set.all()
posts = []
for post in posts_queryset:
try:
bp = post.betterpost
posts.append(bp)
except BetterPost.DoesNotExist:
posts.append(post)
context['posts'] = posts

You can imagine that if you have several subclasses of Post this could get
pretty annoying.  I'd probably write a separate method to return the most
specific instance of an object that I could.

On Thu, Jun 23, 2011 at 5:54 PM, Rich Jones  wrote:

> Even ignoring the select_related then - the fact is that
>
> user.post_set works and user.betterpost_set won't work, seemingly as
> the result of using model inheritance.
>
> Perhaps I could get all of the posts (post and betterposts) and then
> filter by time? Does that make sense / is there a way to do that in
> the template?
>
> R
>
> On Jun 23, 5:40 pm, Micky Hulse  wrote:
> > On Thu, Jun 23, 2011 at 2:17 PM, bruno desthuilliers
> >
> >  wrote:
> > > FWIW, I have been using model inheritance - abstract and concrete - in
> > > half a dozen projects, with about 30 model subclasses in one of them,
> > > and it JustWorks(tm).
> >
> > That sounds pretty sweet! :D
> >
> > I would love to see some examples.
> >
> > I have been using abstract models for some of my projects... I find
> > them extremely useful:
> >
> > https://gist.github.com/1043698
> >
> > It works for me... Of course, I am still a noobie to Python/Django, so
> > may the feedback be kind. :: crosses fingers :: :D
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
+1 on this new feature.

For those that don't understand how this impacts performance, I'm dedicating
a chunk of the (soon to come) webcast to explaining how this works and the
future ideas for monkey-patching the ORM with deferred execution (which
basically means to make this a 99% drop-in replacement).

For those testing this new DSE feature, please remember to use manual
transactions, perform dryrun's first, and keep the chunk size low (as these
are all factors which need to be changed based on what your data is, and
what you are doing with it).

Cal

On Fri, Jun 24, 2011 at 12:32 AM, Thomas Weholt wrote:

> For the impatient:
>
> http://pypi.python.org/pypi/dse/3.0.0.Beta-1
> Source at https://bitbucket.org/weholt/dse2/src
> Modified BSD license.
>
> New in the 3.x version of DSE is the bulk_update-method, more
> intuitive syntax and code clean up.
> NB! The new syntax is not backwards compatible so existing code using
> DSE must be updated to work.
>
> New syntax:
>
>with Person.delayed as d:
>d.insert({'name': 'Thomas', 'age': 36, 'sex': 'M'})
>d.update({'id': 1, 'name': 'John'})
>d.delete(10) # Deletes record with id 10
>
> I hope the syntax is more intuitive and easy to read. Comments wanted.
>
> Bulk update It takes a dictionary of values to update, requires a
> value for the primary key/id of the record, but uses the django orm's
> own update method
> instead of plain sql to reduce number of statements to execute. This
> is helpful when your fields can have a limited set of values, like
> EXIF-data from photos or metadata from mp3s.
>
> An example::
>
>with Photo.delayed as d:
>d.update({'id': 1, 'camera_model': 'Nikon', 'fnumber': 2.8,
> 'iso_speed': 200})
>d.update({'id': 2, 'camera_model': 'Nikon', 'fnumber': 11,
> 'iso_speed': 400})
>d.update({'id': 3, 'camera_model': 'Nikon', 'fnumber': 2.8,
> 'iso_speed': 400})
>d.update({'id': 4, 'camera_model': 'Canon', 'fnumber': 3.5,
> 'iso_speed': 200})
>d.update({'id': 5, 'camera_model': 'Canon', 'fnumber': 11,
> 'iso_speed': 800})
>d.update({'id': 6, 'camera_model': 'Pentax', 'fnumber': 11,
> 'iso_speed': 800})
>d.update({'id': 7, 'camera_model': 'Sony', 'fnumber': 3.5,
> 'iso_speed': 1600})
># and then some thousand more lines like that
>
> Internally DSE will construct a structure like this::
>
>bulk_updates = {
>'camera_model': {
>'Nikon': [1,2,3],
>'Canon': [4,5],
>'Pentax': [6],
>'Sony': [7],
>},
>'fnumber': {
>2.8: [1,3],
>11: [2,5,6],
>3.5: [4,7],
>},
>'iso_speed': {
>200: [1,4],
>400: [2,3],
>800: [5,6],
>1600: [7]
>}
>}
>
> And then execute those statements using::
>
># pk = the primary key field for the model, in most cases id
>for field, values in bulk_updates.iteritems():
>for value, ids in values.iteritems():
>model.objects.filter(**{"%s__in" % pk:
> ids}).update(**{field: value})
>
> For huge datasets where the fields can have limited values this has a
> big impact on performance. So when to use
> update or bulk_update depends on the data you want to process. For
> instance importing a contact list where most
> of the fields had almost unique values would benefit from the
> update-method, but importing data from photos, id3-tags
> from your music collection etc would process much faster using bulk_update.
>
> Thanks to Cal Leeming [Simplicity Media Ltd] for inspiration on this one
> :-)
>
> --
> Mvh/Best regards,
> Thomas Weholt
> http://www.weholt.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 9:28 AM, Cal Leeming [Simplicity Media Ltd]
 wrote:
> +1 on this new feature.
> For those that don't understand how this impacts performance, I'm dedicating
> a chunk of the (soon to come) webcast to explaining how this works and the
> future ideas for monkey-patching the ORM with deferred execution (which
> basically means to make this a 99% drop-in replacement).
> For those testing this new DSE feature, please remember to use manual
> transactions, perform dryrun's first, and keep the chunk size low (as these
> are all factors which need to be changed based on what your data is, and
> what you are doing with it).

For the record, Alex Gaynor prepared a patch at DjangoCon Europe that
adds bulk inserts to Django's ORM.

http://paste.pocoo.org/show/404031/

In brief, it means that:

>>> Entry.objects.bulk_create([
... Entry(headline="Django 1.0 Released"),
... Entry(headline="Django 1.1 Announced"),
... Entry(headline="Breaking: Django is awesome")
... ])

will insert three objects with a single SQL INSERT statement (there
are a couple of other caveats; see the patch for details and docs).

The upside to this -- using bulk inserts for just the permissions
table resulted in a 30% speedup for the PostgreSQL test suite.

The patch has been sitting in my review pile since the conference; as
soon as I get a few spare seconds to scratch myself, I intend to
review it so we can get it into trunk. If anyone else wants to review,
they're most welcome to do so.

Yours,
Russ Magee %-)

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



Re: Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Cal Leeming [Simplicity Media Ltd]
On Fri, Jun 24, 2011 at 2:34 AM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> On Fri, Jun 24, 2011 at 9:28 AM, Cal Leeming [Simplicity Media Ltd]
>  wrote:
> > +1 on this new feature.
> > For those that don't understand how this impacts performance, I'm
> dedicating
> > a chunk of the (soon to come) webcast to explaining how this works and
> the
> > future ideas for monkey-patching the ORM with deferred execution (which
> > basically means to make this a 99% drop-in replacement).
> > For those testing this new DSE feature, please remember to use manual
> > transactions, perform dryrun's first, and keep the chunk size low (as
> these
> > are all factors which need to be changed based on what your data is, and
> > what you are doing with it).
>
> For the record, Alex Gaynor prepared a patch at DjangoCon Europe that
> adds bulk inserts to Django's ORM.
>
> http://paste.pocoo.org/show/404031/
>
> In brief, it means that:
>
>>>> Entry.objects.bulk_create([
>... Entry(headline="Django 1.0 Released"),
>... Entry(headline="Django 1.1 Announced"),
>... Entry(headline="Breaking: Django is awesome")
>... ])
>

Oh, that's a big game changer then. If bulk_create() is considered for the
core, then that means we have a real good chance of getting bulk_update()
considered too. But, some thought would need to go into how the syntax
looks.. My guess is it would either be a monkey patch with some defers, then
a call to bulk_update() at the end (how the hell this would work into
automated transaction management I don't know). Or, it'd be a set of new
functions (i.e. start_bulk_update(), add_bulk_update(),
execute_bulk_update() ), or something like that..

Russell, should we get a ticket created for bulk_update to discuss how this
should be done? Or should a proposal be drawn up first and submitted for
comments?


> will insert three objects with a single SQL INSERT statement (there
> are a couple of other caveats; see the patch for details and docs).
>
> The upside to this -- using bulk inserts for just the permissions
> table resulted in a 30% speedup for the PostgreSQL test suite.
>
> The patch has been sitting in my review pile since the conference; as
> soon as I get a few spare seconds to scratch myself, I intend to
> review it so we can get it into trunk. If anyone else wants to review,
> they're most welcome to do so.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Error while trying to link up to a view from search results in a template .

2011-06-23 Thread Satyajit Sarangi
My views.py is this

def map_display(request):
 if request.method == 'POST':
form = DispForm(request.POST)
if form.is_valid():
this_user = request.user
user1= this_user.pk
LName = form.cleaned_data['LayerName']
a = OsmLayers()
a = OsmLayers.objects.get(Layername=LName)
uperm = PermiLayer()
perml=uperm.objects.get(user_id__exact=pk,table=a.pk)
if perml.permi == "100":

lcount = OsmLayers()
lcount= OsmLayers.objects.get(pk=tab_id)
form1 = 
ReadOnlyForm(initial={"geomcollection":
lcount.geompoly})

return 
render_to_response('Osmdisplay.html',
{'form':form1})
if perml.permi == "110":
lcount = OsmLayers()
lcount= OsmLayers.objects.get(pk=a.pk)
form1 = 
WriteOnlyForm(initial={"geomcollection":
lcount.geompoly})
return render_to_response('Osmmaps.html', 
{'form':form})


I am linking to it from a template which generates search data like
this




{% block content %}


{% for d in data %}

{% url osmdisp arg=d  as the_url %}
{{d.Layername}}

{% endfor %}
{% endblock %}

What I want to do is pass the d.Layername to the view so that it can
be used there .
But , it is just linking me back to the old mapsearch.html

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



Re: Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 9:44 AM, Cal Leeming [Simplicity Media Ltd]
 wrote:
>
>
> On Fri, Jun 24, 2011 at 2:34 AM, Russell Keith-Magee
>  wrote:
>>
>> On Fri, Jun 24, 2011 at 9:28 AM, Cal Leeming [Simplicity Media Ltd]
>>  wrote:
>> > +1 on this new feature.
>> > For those that don't understand how this impacts performance, I'm
>> > dedicating
>> > a chunk of the (soon to come) webcast to explaining how this works and
>> > the
>> > future ideas for monkey-patching the ORM with deferred execution (which
>> > basically means to make this a 99% drop-in replacement).
>> > For those testing this new DSE feature, please remember to use manual
>> > transactions, perform dryrun's first, and keep the chunk size low (as
>> > these
>> > are all factors which need to be changed based on what your data is, and
>> > what you are doing with it).
>>
>> For the record, Alex Gaynor prepared a patch at DjangoCon Europe that
>> adds bulk inserts to Django's ORM.
>>
>> http://paste.pocoo.org/show/404031/
>>
>> In brief, it means that:
>>
>>    >>> Entry.objects.bulk_create([
>>    ...     Entry(headline="Django 1.0 Released"),
>>    ...     Entry(headline="Django 1.1 Announced"),
>>    ...     Entry(headline="Breaking: Django is awesome")
>>    ... ])
>
> Oh, that's a big game changer then. If bulk_create() is considered for the
> core, then that means we have a real good chance of getting bulk_update()
> considered too. But, some thought would need to go into how the syntax
> looks.. My guess is it would either be a monkey patch with some defers, then
> a call to bulk_update() at the end (how the hell this would work into
> automated transaction management I don't know). Or, it'd be a set of new
> functions (i.e. start_bulk_update(), add_bulk_update(),
> execute_bulk_update() ), or something like that..
> Russell, should we get a ticket created for bulk_update to discuss how this
> should be done? Or should a proposal be drawn up first and submitted for
> comments?

I think some mailing list discussion is warranted -- bulk insert has a
clear and obvious SQL interpretation; it isn't immediately clear to me
what bulk-update means from a SQL perspective, and why it isn't just a
thin layer of data manipulation over the top of a couple of existing
Django update calls.

For the record, #7596 is the ticket for bulk insert.

Yours,
Russ Magee %-)

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Fabian Ezequiel Gallina
2011/6/23 Russell Keith-Magee :
> On Fri, Jun 24, 2011 at 12:49 AM, Cal Leeming [Simplicity Media Ltd]
>  wrote:
>>
>>
>> On Thu, Jun 23, 2011 at 5:46 PM, Shawn Milochik  wrote:
>>>
>>> On 06/23/2011 12:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:

 The perfect link to refer these users to:

 http://www.catb.org/~esr/faqs/smart-questions.html
 

 (props to harryr for finding this)

>>>
>>> Yeah. I used to post that link pretty frequently until I was asked to
>>> stop. ;o)
>>
>> Lmao, I won't re-post this again then ;p
>>
>>>
>>> I still think it's a great essay. If I remember correctly, the objection
>>> to it was that the tone wasn't necessarily at the same level of acceptance
>>> and friendliness we like to maintain in this group.
>>>
>>> We should distill it into a shorter, newbie-friendly version and get it
>>> posted somewhere official so we can refer to it.
>>
>> That's be pretty cool. But my guess is that the maintainers just want us to
>> reply with a "you need to give us more information before we can help you"
>> speech, in a non-insulting tone. Shame, takes all the fun out of it lol.
>> 
>
> The tone is exactly why I've asked people to stop referring to ESR's
> document. The spirit of the document -- that you can only get good
> answers if you ask good questions -- is certainly valid, but to me,
> ESR's tone in that document really comes off as "Stop wasting my time,
> which is more valuable than yours, because I'm a hacker, which means
> I'm awesome and you're not". I'm sorry, but being a 1337 h4X0R doesn't
> give you carte blanche to treat anyone else like crap.
>
> The Django core team have tried really hard to foster a positive,
> accepting community culture. Everyone is a beginner once, and everyone
> occasionally posts in haste and forgets to include salient details.
> Absolutely nothing is gained by insulting a newcomer to the community.
>
> As a side note, if someone were to redraft that document in such a way
> that it *doesn't* have that tone, I'd gladly include the text in
> Django's own documentation.
>
> Yours,
> Russ Magee %-)
>

I find this document[0] to be really nice, helpful and without that
particular tone.

Someone from Python Argentina (PyAR) translated it to Spanish and it
is what we use to guide newcomers.

[0] http://www.mikeash.com/getting_answers.html


Regards,
-- 
Fabián E. Gallina
http://www.anue.biz

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



Re: Django password_change

2011-06-23 Thread Yuri Piratello
I use in that project

https://github.com/yuripiratello/nilo

(r'^alterarSenha/$', 'nilo.views.alterarSenha'),

My template: /templates/alterarSenha.html

Att;

Yuri Zanola Piratello
=
blog: http://yuri-piratello.blogspot.com 
msn: yuri_zp...@hotmail.com
Skype: yuri_zpira
Gmail: yuri.pirate...@gmail.com
Twitter: http://twitter.com/yuri_zpira
GNU/Linux user number: 530410



On Thu, Jun 23, 2011 at 3:53 PM, Mark L.  wrote:

> Hey guys, I'm a newb to Django, but have some experience with Rails.
> Its fun to see the similarities and differences in both!
>
> After looking through
> https://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.views
> Under the section 'Other built-in views' I think password change is
> what I want. I did find this on stackoverflow...
>
>
> http://stackoverflow.com/questions/388800/django-how-do-i-use-the-built-in-password-reset-change-views-with-my-own-templat
>
> ...this focuses on password_reset, but I'm thinking it would apply
> also to password_change.
>
> So in my urls.py I added these 2 lines...
>
> (r'^/accounts/password/change/$',
> 'django.contrib.auth.views.password_change',
>{'post_change_redirect' :
> 'django.contrib.auth.views.password_reset_done'}),
>
>
> ...and I also copied password_change_form.html and
> password_change_done.html to /templates/registration/
> So after logging in to my system I'm simply trying to go to the /
> accounts/password/change/ url. Oh course I'm getting a 404. So I'm not
> sure how close I am, but I would appreciate any ideas. Thanx!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Creating simple view app based on Admin site

2011-06-23 Thread Alexei
Hi,

I'm trying to create a simple application whose most important feature
is going to be to view/search the contents of my database.  I have the
Admin site configured to exactly how I want the end product to look
(searching, filtering, etc.) but I'm having trouble porting this over
to the user (public) side of the app.  I figured I would just subclass
the Admin classes, or just straight-up copy and paste the Admin code
and modify it from there, but it turned out to not be so simple.

What's the easiest way to display the database to the end-user the
same way that the Admin interface does (without edit capabilities)?
It feels like such a waste to write everything from scratch when I
have what I want the end product to look like right in front of me.

-Alexei

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



django 1.3 timing out on empty POST request

2011-06-23 Thread mehdi ait oufkir
Hello,

I recently upgraded to django 1.3 and POST request with empty body
seem to timeout.

This call :
 block = getattr(request, POST, { })
seems to never return, when the request is POST request with an empty
body.

Let me know if you think you know what's going on.
Thanks!

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



Re: Best practices to secure admin site

2011-06-23 Thread Phui-Hock
> * Only allow HTTPS (to the admin, and perhaps to the entire site).
> * Don't use "/admin/" -- I usually use a separate subdomain like
> "backend.example.com", or sometimes just a different root (I often see
> "nqzva" -- figuring out why is left as an exercise for the reader :).
> * Limit access based on IP, when appropriate -- many corporate
> settings will already have a VPN, for example, so piggyback on that if
> possible.

Hi Jacop,
Thanks for the advice, and nqzva seems like a fun way to obscure admin
url :)
However, I ended up using a different port number and
enforce cert based authentication on top of the default login form.

Managing own CA is no fun, and it's easy to screw things up.

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Kenneth Gonsalves
On Fri, 2011-06-24 at 08:14 +0800, Russell Keith-Magee wrote:
> s a side note, if someone were to redraft that document in such a way
> that it *doesn't* have that tone, I'd gladly include the text in
> Django's own documentation. 

last time you posted on this topic you had given a link to something
that was more appropriate - could you repost it please?
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 11:33 AM, Kenneth Gonsalves
 wrote:
> On Fri, 2011-06-24 at 08:14 +0800, Russell Keith-Magee wrote:
>> s a side note, if someone were to redraft that document in such a way
>> that it *doesn't* have that tone, I'd gladly include the text in
>> Django's own documentation.
>
> last time you posted on this topic you had given a link to something
> that was more appropriate - could you repost it please?

I think this is the link you're referring to:

http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

It's not *completely* on topic -- it's about reporting bugs, rather
than asking questions. However, it gets the tone right, and many of
the lessons about submitting useful bug reports are equally applicable
to asking questions.

Yours,
Russ Magee %-)

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 10:17 AM, Fabian Ezequiel Gallina
 wrote:
> 2011/6/23 Russell Keith-Magee :
>> On Fri, Jun 24, 2011 at 12:49 AM, Cal Leeming [Simplicity Media Ltd]
>>  wrote:
>>>
>>>
>>> On Thu, Jun 23, 2011 at 5:46 PM, Shawn Milochik  wrote:

 On 06/23/2011 12:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:
>
> The perfect link to refer these users to:
>
> http://www.catb.org/~esr/faqs/smart-questions.html
> 
>
> (props to harryr for finding this)
>

 Yeah. I used to post that link pretty frequently until I was asked to
 stop. ;o)
>>>
>>> Lmao, I won't re-post this again then ;p
>>>

 I still think it's a great essay. If I remember correctly, the objection
 to it was that the tone wasn't necessarily at the same level of acceptance
 and friendliness we like to maintain in this group.

 We should distill it into a shorter, newbie-friendly version and get it
 posted somewhere official so we can refer to it.
>>>
>>> That's be pretty cool. But my guess is that the maintainers just want us to
>>> reply with a "you need to give us more information before we can help you"
>>> speech, in a non-insulting tone. Shame, takes all the fun out of it lol.
>>> 
>>
>> The tone is exactly why I've asked people to stop referring to ESR's
>> document. The spirit of the document -- that you can only get good
>> answers if you ask good questions -- is certainly valid, but to me,
>> ESR's tone in that document really comes off as "Stop wasting my time,
>> which is more valuable than yours, because I'm a hacker, which means
>> I'm awesome and you're not". I'm sorry, but being a 1337 h4X0R doesn't
>> give you carte blanche to treat anyone else like crap.
>>
>> The Django core team have tried really hard to foster a positive,
>> accepting community culture. Everyone is a beginner once, and everyone
>> occasionally posts in haste and forgets to include salient details.
>> Absolutely nothing is gained by insulting a newcomer to the community.
>>
>> As a side note, if someone were to redraft that document in such a way
>> that it *doesn't* have that tone, I'd gladly include the text in
>> Django's own documentation.
>>
>> Yours,
>> Russ Magee %-)
>>
>
> I find this document[0] to be really nice, helpful and without that
> particular tone.
>
> Someone from Python Argentina (PyAR) translated it to Spanish and it
> is what we use to guide newcomers.
>
> [0] http://www.mikeash.com/getting_answers.html

Nice! I haven't seen that one before -- thanks for sharing!

Yours,
Russ Magee %-)

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



Re: Tests got ~10x slower after upgrading to Django 1.3

2011-06-23 Thread Cesar Canassa
Hi Russ!

I did some more testing, I found out that each test is taking an extra ~1s
to run, no matter the test size. See this TestCase for example, it
takes 4.067s to run.

from django.test import TestCase

class JobTest(TestCase):
def test_1(self):
pass

def test_2(self):
pass

def test_3(self):
pass

def test_4(self):
pass

I noticed that if I replace the django.test.TestCase with
the django.utils.unittest.TestCase the time drops to 0.009s I think that the
problem lies in the TransactionTestCase._fixture_setup method:

def _fixture_setup(self):
# If the test case has a multi_db=True flag, flush all databases.
# Otherwise, just flush default.
if getattr(self, 'multi_db', False):
databases = connections
else:
databases = [DEFAULT_DB_ALIAS]
for db in databases:
call_command('flush', verbosity=0, interactive=False,
database=db)

if hasattr(self, 'fixtures'):
# We have to use this slightly awkward syntax due to the
fact
# that we're using *args and **kwargs together.
call_command('loaddata', *self.fixtures, **{'verbosity': 0,
'database': db})

The flush is what takes ~1s to run, If I comment that line the time drops to
almost zero seconds.

Does this makes any sense? Did the Django 1.3 changed this behavior?

I am downloading the Django 1.2.5 source to do more investigation.


Best regards,
Cesar Canassa

2011/6/21 Russell Keith-Magee 

> On Wed, Jun 22, 2011 at 1:31 AM, Cesar Canassa 
> wrote:
> > I am working in a large Django project that is currently using the 1.2.3
> > version. The project test suite has around 500 test which take ~50
> seconds
> > to run in my machine.
> > I recently did a upgrade to the Django 1.3 version, the upgrade was
> smooth
> > so far, most problems came from the SQL Server driver but these are not
> used
> > in the test suite, since the test database is SQLite. The only thing I
> had
> > to change in the project itself was removing the jogging app since the
> 1.3
> > has built-in logging facilities.
> > The problem is that the test suite now takes ~500 seconds to run, that's
> > about 10 times longer than it did with the 1.2.3 version.
> > Has anyone had a similar issue? I have a felling that this related to
> > running Django under Windows.
>
> I can't say I've heard any such reports -- if anything, 1.3 testing
> should be faster, due to a number of optimizations in the test startup
> process.
>
> If you identify the source of the slowdown, I'd be interested in
> hearing about it in case it is a serious regression on Django's part.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Social Networking basics? -Raj

2011-06-23 Thread Peter Murphy
+1 for Fabián's link. Not only is it better-tempered than ESR on the
subject, it's a lot _shorter_. I like how it is split into 10 simple
sections. Love points 4, 5 and 6!

Not everyone on this list has English as a first language. Some
newcomers may be confused or daunted by Eric's lengthy prose, and thus
missing the point altogether. But I think Mike Ash's work can be
skimmed to get the gist.

Cheers,
Peter

On Jun 24, 12:17 pm, Fabian Ezequiel Gallina 
wrote:
>
> I find this document[0] to be really nice, helpful and without that
> particular tone.
>
> Someone from Python Argentina (PyAR) translated it to Spanish and it
> is what we use to guide newcomers.
>
> [0]http://www.mikeash.com/getting_answers.html
>
> Regards,
> --
> Fabián E. Gallinahttp://www.anue.biz

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



Re: Tests got ~10x slower after upgrading to Django 1.3

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 11:54 AM, Cesar Canassa  wrote:
> Hi Russ!
> I did some more testing, I found out that each test is taking an extra ~1s
> to run, no matter the test size. See this TestCase for example, it
> takes 4.067s to run.
> from django.test import TestCase
> class JobTest(TestCase):
>     def test_1(self):
>         pass
>     def test_2(self):
>         pass
>     def test_3(self):
>         pass
>     def test_4(self):
>         pass
> I noticed that if I replace the django.test.TestCase with
> the django.utils.unittest.TestCase the time drops to 0.009s I think that the
> problem lies in the TransactionTestCase._fixture_setup method:
>     def _fixture_setup(self):
>         # If the test case has a multi_db=True flag, flush all databases.
>         # Otherwise, just flush default.
>         if getattr(self, 'multi_db', False):
>             databases = connections
>         else:
>             databases = [DEFAULT_DB_ALIAS]
>         for db in databases:
>             call_command('flush', verbosity=0, interactive=False,
> database=db)
>             if hasattr(self, 'fixtures'):
>                 # We have to use this slightly awkward syntax due to the
> fact
>                 # that we're using *args and **kwargs together.
>                 call_command('loaddata', *self.fixtures, **{'verbosity': 0,
> 'database': db})
> The flush is what takes ~1s to run, If I comment that line the time drops to
> almost zero seconds.
> Does this makes any sense? Did the Django 1.3 changed this behavior?
> I am downloading the Django 1.2.5 source to do more investigation.

Thanks for that analysis, Cesar.

Flush has always been a bit of a performance hole -- especially on
MySQL MyISAM. However, I'm not aware of any change we made in 1.3 that
should make any worse than it was in 1.2. The biggest factor affecting
the speed of a flush (that I'm aware of) is the number of tables to be
flushed; as Django's test suite has gotten bigger, the suite as a
whole has gotten exponentially slower, as more tests means more test
models to flush. However, this factor shouldn't affect an A/B test
between 1.2 and 1.3 of the same test suite.

Good luck narrowing this down some more :-)

Yours,
Russ Magee %-)

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



Re: Ann: DSE v.3.0.0 Beta #1

2011-06-23 Thread Thomas Weholt
On Fri, Jun 24, 2011 at 3:54 AM, Russell Keith-Magee
 wrote:
> On Fri, Jun 24, 2011 at 9:44 AM, Cal Leeming [Simplicity Media Ltd]
>  wrote:
>>
>>
>> On Fri, Jun 24, 2011 at 2:34 AM, Russell Keith-Magee
>>  wrote:
>>>
>>> On Fri, Jun 24, 2011 at 9:28 AM, Cal Leeming [Simplicity Media Ltd]
>>>  wrote:
>>> > +1 on this new feature.
>>> > For those that don't understand how this impacts performance, I'm
>>> > dedicating
>>> > a chunk of the (soon to come) webcast to explaining how this works and
>>> > the
>>> > future ideas for monkey-patching the ORM with deferred execution (which
>>> > basically means to make this a 99% drop-in replacement).
>>> > For those testing this new DSE feature, please remember to use manual
>>> > transactions, perform dryrun's first, and keep the chunk size low (as
>>> > these
>>> > are all factors which need to be changed based on what your data is, and
>>> > what you are doing with it).
>>>
>>> For the record, Alex Gaynor prepared a patch at DjangoCon Europe that
>>> adds bulk inserts to Django's ORM.
>>>
>>> http://paste.pocoo.org/show/404031/
>>>
>>> In brief, it means that:
>>>
>>>    >>> Entry.objects.bulk_create([
>>>    ...     Entry(headline="Django 1.0 Released"),
>>>    ...     Entry(headline="Django 1.1 Announced"),
>>>    ...     Entry(headline="Breaking: Django is awesome")
>>>    ... ])
>>
>> Oh, that's a big game changer then. If bulk_create() is considered for the
>> core, then that means we have a real good chance of getting bulk_update()
>> considered too. But, some thought would need to go into how the syntax
>> looks.. My guess is it would either be a monkey patch with some defers, then
>> a call to bulk_update() at the end (how the hell this would work into
>> automated transaction management I don't know). Or, it'd be a set of new
>> functions (i.e. start_bulk_update(), add_bulk_update(),
>> execute_bulk_update() ), or something like that..
>> Russell, should we get a ticket created for bulk_update to discuss how this
>> should be done? Or should a proposal be drawn up first and submitted for
>> comments?
>
> I think some mailing list discussion is warranted -- bulk insert has a
> clear and obvious SQL interpretation; it isn't immediately clear to me
> what bulk-update means from a SQL perspective, and why it isn't just a
> thin layer of data manipulation over the top of a couple of existing
> Django update calls.
>
> For the record, #7596 is the ticket for bulk insert.
>
> Yours,
> Russ Magee %-)

Just the fact that there is a discussion about adding features like
this to the django core makes this a very good morning :-). FYI: My
testing indicated that updates had the biggest performance gain from
DSE or similar concepts.

Anyway, this is great news Russ.

Thomas

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



Re: Tests got ~10x slower after upgrading to Django 1.3

2011-06-23 Thread Cesar Canassa
I think I solved this! The reason why the test cases were taking so long was
because Django was not enabling the transaction support, so the tests were
falling back to the non-transaction TestCase

My project has two test databases but the 'log' is not used anymore so I
didn't care if it was created or not:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
},

'log': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

When the tests run it calls the following method:

def connections_support_transactions():
"""
Returns True if all connections support transactions.  This is messy
because 2.4 doesn't support any or all.
"""
return all(conn.features.supports_transactions
for conn in connections.all())

In Django 1.2.3 this method returns all([True, True]) and in Django 1.3 it
returns all([True, None])

The problem is that in my test settings I used the same database name
':memory:' on both databases. When this happens in Django 1.2.3 it
initialize the both databases, but in Django 1.3 it doesn't initialize the
second. I just had to change the names and now the tests are running back in
the usual speed!

This was very hard to debbug, maybe Django should include a warning message
in case someone tries to do this mistake again?


Thanks!
Cesar Canassa

2011/6/24 Russell Keith-Magee 

> On Fri, Jun 24, 2011 at 11:54 AM, Cesar Canassa 
> wrote:
> > Hi Russ!
> > I did some more testing, I found out that each test is taking an extra
> ~1s
> > to run, no matter the test size. See this TestCase for example, it
> > takes 4.067s to run.
> > from django.test import TestCase
> > class JobTest(TestCase):
> > def test_1(self):
> > pass
> > def test_2(self):
> > pass
> > def test_3(self):
> > pass
> > def test_4(self):
> > pass
> > I noticed that if I replace the django.test.TestCase with
> > the django.utils.unittest.TestCase the time drops to 0.009s I think that
> the
> > problem lies in the TransactionTestCase._fixture_setup method:
> > def _fixture_setup(self):
> > # If the test case has a multi_db=True flag, flush all databases.
> > # Otherwise, just flush default.
> > if getattr(self, 'multi_db', False):
> > databases = connections
> > else:
> > databases = [DEFAULT_DB_ALIAS]
> > for db in databases:
> > call_command('flush', verbosity=0, interactive=False,
> > database=db)
> > if hasattr(self, 'fixtures'):
> > # We have to use this slightly awkward syntax due to the
> > fact
> > # that we're using *args and **kwargs together.
> > call_command('loaddata', *self.fixtures, **{'verbosity':
> 0,
> > 'database': db})
> > The flush is what takes ~1s to run, If I comment that line the time drops
> to
> > almost zero seconds.
> > Does this makes any sense? Did the Django 1.3 changed this behavior?
> > I am downloading the Django 1.2.5 source to do more investigation.
>
> Thanks for that analysis, Cesar.
>
> Flush has always been a bit of a performance hole -- especially on
> MySQL MyISAM. However, I'm not aware of any change we made in 1.3 that
> should make any worse than it was in 1.2. The biggest factor affecting
> the speed of a flush (that I'm aware of) is the number of tables to be
> flushed; as Django's test suite has gotten bigger, the suite as a
> whole has gotten exponentially slower, as more tests means more test
> models to flush. However, this factor shouldn't affect an A/B test
> between 1.2 and 1.3 of the same test suite.
>
> Good luck narrowing this down some more :-)
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Tests got ~10x slower after upgrading to Django 1.3

2011-06-23 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 2:08 PM, Cesar Canassa  wrote:
> I think I solved this! The reason why the test cases were taking so long was
> because Django was not enabling the transaction support, so the tests were
> falling back to the non-transaction TestCase
> My project has two test databases but the 'log' is not used anymore so I
> didn't care if it was created or not:
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.sqlite3',
>         'NAME': ':memory:',
>     },
>     'log': {
>         'ENGINE': 'django.db.backends.sqlite3',
>         'NAME': ':memory:',
>     }
> }
> When the tests run it calls the following method:
> def connections_support_transactions():
>     """
>     Returns True if all connections support transactions.  This is messy
>     because 2.4 doesn't support any or all.
>     """
>     return all(conn.features.supports_transactions
>         for conn in connections.all())
> In Django 1.2.3 this method returns all([True, True]) and in Django 1.3 it
> returns all([True, None])
> The problem is that in my test settings I used the same database name
> ':memory:' on both databases. When this happens in Django 1.2.3 it
> initialize the both databases, but in Django 1.3 it doesn't initialize the
> second. I just had to change the names and now the tests are running back in
> the usual speed!
> This was very hard to debbug, maybe Django should include a warning message
> in case someone tries to do this mistake again?

Ah - you didn't say you had two databases. There *were* some very
important changes made to the test setup mechanism for 1.3 when
multiple databases are involved, and they certainly explain the
behavior you're seeing.

Under 1.2.X, if you have multiple databases, and multiple entries
pointed to the same database name, the test database would be
initialized twice. If you were using an on-disk database (rather than
:memory:), this would lead to the creation of *two* test databases,
instead of one test database with two connections. To make matters
worse, under certain conditions, the teardown process would cause the
*production* database to be dropped.

In 1.3, we use a combination of database name, host, port and engine
(and, in the case of Oracle, the username as well) to identify the
'unique' databases, and ensures that each of these test databases are
only initialized once, and the connections are then patched to make
sure you have multiple connections to a single database.

So - it sounds like you might have found a bug, not just something
that needs to be documented. :memory: databases don't behave quite
like on-disk databases, but we don't have any special handling in
place to account for that fact.

If you could open a ticket for this, I'd be much obliged.

It sounds like you've found a temporary workaround; for the record,
another workaround would be to put *anything* into the HOST or PORT
settings for your database. That would be enough to mark the two
databases as distinct from the perspective of the test setup
mechanism.

Yours,
Russ Magee %-)

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