Setting default form value in template

2011-08-24 Thread raj
I'm trying to set a default form value in the template, and not in the
forms.py file (because I'm trying to make the default value dynamic
depending on something that javascript will return).
So To test it, I have the following line in my template:

{{ form.first_name|default:"Enter Your first name" }}

The issue is that it doesn't work, And I can't figure out why. Am I
doing something illegal?
Help Please. 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: Error: cannot import name settings

2011-08-24 Thread Mario Gudelj
Thanks for your help guys.

It seems that there is an issue in django_countries app where the fields.py
file has "from django_countries import settings", but there's no settings.py
file inside the django_countries folder. When I comment out that line the
project validates.

I wish that the error message was a bit nicer :(

Cheers,


On 25 August 2011 11:26, Kejun He  wrote:

> Search "settings" in your project, and see the settings how to be imported.
>
>
>
> On Wed, Aug 24, 2011 at 4:45 PM, Reinout van Rees wrote:
>
>> On 24-08-11 09:54, Mario Gudelj wrote:
>>
>>> Error: cannot import name settings
>>>
>>
>> Are you doing "from django.conf import settings"? Is that going wrong?
>> Or does django refuse to start? If so, what's your settings environment
>> variable like?
>>
>> And: can you give the full traceback?
>>
>>
>> Reinout
>>
>> --
>> Reinout van Reeshttp://reinout.vanrees.org/
>> rein...@vanrees.org 
>> http://www.nelen-schuurmans.**nl/
>> "If you're not sure what to do, make something. -- Paul Graham"
>>
>>
>> --
>> 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.
>

-- 
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: How to add CSRF to context when using test client???

2011-08-24 Thread Matteius
Thanks for both suggestions, I recently tried this approach and
reached success when I ran my tests.  So I think this is the correct
approach and I'll include this CSRF style testing with my test suite
now.

-Matteius

On Jul 7, 6:02 am, Craig Blaszczyk  wrote:
> csrf_token is a proxy object not a string.
>
> Try doing:
> csrf_token = '%s' % response.context['csrf_token']

-- 
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.



Customizing the admin form

2011-08-24 Thread Cu7l4ss
Hi,

I have customized a model admin form, editing the label_for_instance for a 
ForeignKey field and a MultiChoice Field.
As a result the plus button was gone. How can I insert it back? (didn't find 
anything in the documentation)

Couple more questions:
1. I have a django mptt key and when I edit I can pick the same element(how 
can I populate it without the one that I edit)
2. How can I add descriptions for the fields
3. How can I remove the validation of certain elements and insert my own(I'm 
using a slug field and it doesnt accept anything but ascii, I fixed it so it 
would work with utf8 but the validation remained)


Thanks !!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/HsrZW2uhRUkJ.
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: Error: cannot import name settings

2011-08-24 Thread Kejun He
Search "settings" in your project, and see the settings how to be imported.


On Wed, Aug 24, 2011 at 4:45 PM, Reinout van Rees wrote:

> On 24-08-11 09:54, Mario Gudelj wrote:
>
>> Error: cannot import name settings
>>
>
> Are you doing "from django.conf import settings"? Is that going wrong?
> Or does django refuse to start? If so, what's your settings environment
> variable like?
>
> And: can you give the full traceback?
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> 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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Jianbao Tao
BTW, the virtualenv uses python2.7



On Wed, Aug 24, 2011 at 6:54 PM, Jianbao Tao  wrote:

> Thanks, Tom, Reinout.
>
> I think I forgot to mention the configuration of my machine. Here it is.
>
>- Mac OS Snow Leopard 10.6.8
>- mysql-5.5.14-osx10.6-x86_64
>- Apache2 (shipped with OSX)
>- mod_wsgi 3.3
>
> And here is some additional information that may help.
> 
> >$ file /usr/libexec/apache2/mod_wsgi.so
> /usr/libexec/apache2/mod_wsgi.so: Mach-O universal binary with 2
> architectures
> /usr/libexec/apache2/mod_wsgi.so (for architecture x86_64): Mach-O 64-bit
> bundle x86_64
> /usr/libexec/apache2/mod_wsgi.so (for architecture i386): Mach-O bundle
> i386
>
> >$ otool -L /usr/libexec/apache2/mod_wsgi.so
> /usr/libexec/apache2/mod_wsgi.so:
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
> 125.2.11)
>  /Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility
> version 2.7.0, current version 2.7.0)
> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
> (compatibility version 150.0.0, current version 550.43.0)
> 
>
> And I do use virtualenv. Here is how I enable the virtual environment in
> the .wsgi file.
> 
> """
> Modify sys.path to conform to virtualenv setup.
> The basic idea is to add packages installed in the virtual environment to
> the
> front of sys.path so that python will use them instead of those from the
> system site-packages.
> """
> # Get old sys.path.
> old_sys_path = list(sys.path)
> virt_site_packages = os.path.join(path, siteName,
> 'lib/python2.7/site-packages')
>
> site.addsitedir(virt_site_packages)
>
> # Put the added new paths to the front of sys.path.
> new_sys_path = []
> for item in list(sys.path):
> if item not in old_sys_path:
> new_sys_path.append(item)
> sys.path.remove(item)
>
> sys.path[:0] = new_sys_path
> 
>
> The process is pretty standard, which can be found in the mod_wsgi 
> website
> .
>
> So, any thoughts?
>
>
> On Wed, Aug 24, 2011 at 10:25 AM, Tom Evans wrote:
>
>> On Mon, Aug 22, 2011 at 11:37 PM, Jim  wrote:
>> > Hello folks,
>> > This probably has been discussed many times, but I still can't find any
>> > solution yet. Basically, it turns out that python can load MySQLdb just
>> > fine, but Apache can't load MySQLdb from the wsgi script.
>> > I am using python2.7 in a virtual environment created by virtualenv.
>> Here is
>> > the error info extracted from the Apache error log. To make the lines
>> > shorter, I deleted all the time tags in the brackets.
>> > Any ideas how to fix it?
>> > [] mod_wsgi (pid=3136): Target WSGI script
>> > '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi' cannot be
>> loaded
>> > as Python module.
>> > [] mod_wsgi (pid=3136): Exception occurred processing WSGI script
>> > '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi'.
>> > [] Traceback (most recent call last):
>> > []   File "/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi",
>> line
>> > 56, in 
>> > [] import MySQLdb
>> > []   File
>> > "/Users/jianbao/projects/
>> tao.com/mysite/lib/python2.7/site-packages/MySQLdb/__init__.py",
>> > line 19, in 
>> > [] import _mysql
>> > [] ImportError:
>> > dlopen(/Users/jianbao/projects/
>> tao.com/mysite/lib/python2.7/site-packages/_mysql.so,
>> > 2): Library not loaded: libmysqlclient.18.dylib
>> > []   Referenced from:
>> > /Users/jianbao/projects/
>> tao.com/mysite/lib/python2.7/site-packages/_mysql.so
>> > []   Reason: image not found
>> >
>>
>> Are mysql, python and python-mysql all compiled correctly for the same
>> architecture? IE all 32 bit or all 64 bit.
>>
>> ISTR that this can be a problem on OS X, but I'm not an OS X user...
>>
>>
>> http://stackoverflow.com/questions/1969222/mysql-python-1-2-3-and-os-x-10-5-64-or-32-bit
>>
>> 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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Jianbao Tao
Thanks, Tom, Reinout.

I think I forgot to mention the configuration of my machine. Here it is.

   - Mac OS Snow Leopard 10.6.8
   - mysql-5.5.14-osx10.6-x86_64
   - Apache2 (shipped with OSX)
   - mod_wsgi 3.3

And here is some additional information that may help.

>$ file /usr/libexec/apache2/mod_wsgi.so
/usr/libexec/apache2/mod_wsgi.so: Mach-O universal binary with 2
architectures
/usr/libexec/apache2/mod_wsgi.so (for architecture x86_64): Mach-O 64-bit
bundle x86_64
/usr/libexec/apache2/mod_wsgi.so (for architecture i386): Mach-O bundle i386

>$ otool -L /usr/libexec/apache2/mod_wsgi.so
/usr/libexec/apache2/mod_wsgi.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
125.2.11)
/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility
version 2.7.0, current version 2.7.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
(compatibility version 150.0.0, current version 550.43.0)


And I do use virtualenv. Here is how I enable the virtual environment in the
.wsgi file.

"""
Modify sys.path to conform to virtualenv setup.
The basic idea is to add packages installed in the virtual environment to
the
front of sys.path so that python will use them instead of those from the
system site-packages.
"""
# Get old sys.path.
old_sys_path = list(sys.path)
virt_site_packages = os.path.join(path, siteName,
'lib/python2.7/site-packages')

site.addsitedir(virt_site_packages)

# Put the added new paths to the front of sys.path.
new_sys_path = []
for item in list(sys.path):
if item not in old_sys_path:
new_sys_path.append(item)
sys.path.remove(item)

sys.path[:0] = new_sys_path


The process is pretty standard, which can be found in the mod_wsgi
website
.

So, any thoughts?


On Wed, Aug 24, 2011 at 10:25 AM, Tom Evans wrote:

> On Mon, Aug 22, 2011 at 11:37 PM, Jim  wrote:
> > Hello folks,
> > This probably has been discussed many times, but I still can't find any
> > solution yet. Basically, it turns out that python can load MySQLdb just
> > fine, but Apache can't load MySQLdb from the wsgi script.
> > I am using python2.7 in a virtual environment created by virtualenv. Here
> is
> > the error info extracted from the Apache error log. To make the lines
> > shorter, I deleted all the time tags in the brackets.
> > Any ideas how to fix it?
> > [] mod_wsgi (pid=3136): Target WSGI script
> > '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi' cannot be
> loaded
> > as Python module.
> > [] mod_wsgi (pid=3136): Exception occurred processing WSGI script
> > '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi'.
> > [] Traceback (most recent call last):
> > []   File "/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi",
> line
> > 56, in 
> > [] import MySQLdb
> > []   File
> > "/Users/jianbao/projects/
> tao.com/mysite/lib/python2.7/site-packages/MySQLdb/__init__.py",
> > line 19, in 
> > [] import _mysql
> > [] ImportError:
> > dlopen(/Users/jianbao/projects/
> tao.com/mysite/lib/python2.7/site-packages/_mysql.so,
> > 2): Library not loaded: libmysqlclient.18.dylib
> > []   Referenced from:
> > /Users/jianbao/projects/
> tao.com/mysite/lib/python2.7/site-packages/_mysql.so
> > []   Reason: image not found
> >
>
> Are mysql, python and python-mysql all compiled correctly for the same
> architecture? IE all 32 bit or all 64 bit.
>
> ISTR that this can be a problem on OS X, but I'm not an OS X user...
>
>
> http://stackoverflow.com/questions/1969222/mysql-python-1-2-3-and-os-x-10-5-64-or-32-bit
>
> 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: Problems on using multiple databases

2011-08-24 Thread Jianbao Tao
Reinout,

Thanks so much for your help. I think I have figured out the solution. I
posted it on
https://groups.google.com/forum/?hl=en#!topic/django-users/zwMWNdIqB3A.

Please take a look.

Jianbao

On Wed, Aug 24, 2011 at 10:13 AM, Reinout van Rees wrote:

> On 24-08-11 17:57, Jianbao Tao wrote:
>
>> Now './manage.py syncdb' can run through with no problems. However, it
>> doesn't create the database 'test.sqlite', which means the models in the
>> app, books, are still installed in the default database.
>>
>>
> That's in the django docs: syncdb only managed the main default database by
> default. You'll have to call syncdb on the second database separately.
>
> Often the second database is an existing one that django shouldn't touch,
> that's why the default is that way.
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
> --
> 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.



Tips for setting up multiple databases routing in Django

2011-08-24 Thread Jim
First of all, I would like to thank Reinout van Rees (
http://reinout.vanrees.org/) for his helpful suggestions. 

Suppose you have two databases, 'default' and 'test', and one app, 'books'. 
And you want to store the models in books in the database 'test'. 

According to the guide from Django 
doc, 
you may have something like this in your settings.py:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/path/to/default.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
'test': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/path/to/test.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}


And a routing file, say dbrouting.py, which has something like this:

class DBRouter(object):
def db_for_read(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test' # dbName is a name in settings.DATABASES
else:
dbName = None
return dbName

def db_for_write(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
return dbName

def allow_relation(self, obj1, obj2, **hints):
label1 = obj1._meta.app_label
label2 = obj2._meta.app_label
if label1 == label2:
return True
return None

def allow_syncdb(self, db, model):
# db is a string of database name.
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
if dbName == db:
return True
else:
return False


Now, here is the important stuff. If you don't have the database file 
test.sqlite yet, you must create it first before you enable the database 
routing. Use the following command to do this:

./manage.py syncdb --database=test

With this step, Django will initialize the database, including creating some 
required tables (such as django_content_type). In the routing scheme, only 
models from the app books can access the database 'test'. That means that 
even Django cannot get in the database and make the necessary setups 
including creating some necessary tables. Once you have initialized the 
database, you can enable the routing scheme.

To sum up, here are the steps I recommend if you want to create a database 
to store data from certain models.

   1. Add that new database to settings.py.
   2. Make sure that the database routing is disabled. (To disable the 
   database routing, just comment out the DATABASE_ROUTERS setting in the 
   settings.py file.)
   3. Initialize your new database as shown above.
   4. Enable database routing (by enabling the DATABASE_ROUTERS setting in 
   the settings.py file).
   5. Run ./manage.py syncdb --database= to create 
   tables for your models.
   
In the above steps, I assume you have created your models and database 
routers properly.

That's it.

BTW, I am new to Django. So, if I am missing anything above or having 
anything misleading, please do correct me. Thank you very much.
 



-- 
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/-/3CnRHQefMHAJ.
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: Problem updating data

2011-08-24 Thread Malcolm Box
Instead of counting the inactive, try counting the active ones. If that
count doesn't go up by one, I'd suspect something's dodgy in your Entry
model's save() that means it doesn't write successfully to the db.

You could debug by doing:

from django.db import connection
connection.queries
e1.save()
connection.queries

to see what the SQL generated was.

Then start looking at your database to see what it's doing.

Malcolm

On 23 August 2011 23:08, Karen McNeil  wrote:

> No, that's not the problem. Even if I redo the query now, I still get
> the same count (see below). And, like I said, the change does not show
> up in the admin either -- THE VALUE HAS NOT BEEN CHANGED.
>
> This behavior is so unexpected I'm not sure how to even begin trouble-
> shooting it.
>
> ~Karen
>
> PS -- What's wrong with querying by "active=0"? I did it that way
> because that's what the admin interface does for filters... is there
> any difference?
>
>
> NEW SHELL SESSION FROM TODAY, TESTING SAME THING:
>
> >>> from dictionary.models import Entry
> >>> entries = Entry.objects.filter(active=False)
> >>> entries.count()
> 3642
> >>> e1 = entries[0]
> >>> e1
> 
> >>> e1.active
> False
>
> --
> 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.
>
>


-- 
Malcolm Box
malcolm@gmail.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: Creating an alternative change_list view for a specific app/model, not extending or overriding

2011-08-24 Thread Thomas Orozco
What about calling your admin view with a GET "alternate=1" parameter ?

An if statement in a template override would then allow you to render
properly depending on the aforementioned attribute provided you're passing
the request in the Context.

This event allows you to fine tune which bits you want to change.
Le 24 août 2011 23:38, "Thomas Weholt"  a écrit :
> I want to create a view looking and working just like the admin
> change_list, but using my own template ( based on the admin
> change_list template ) so that all the filtering you get from
> specifiying filtering in your adminmodel still works in my new view. I
> DO NOT want to extend or override the existing one but provide an
> additional/alternative view to the existing change_list for a specific
> app/model. I need to change how the elements in the change_list are
> presented. I'm listing photos, and want a layout like googles image
> search, not the table-based you get by default in the admin. I need to
> do this as well in my alternative view. I want to use the
> date-hierarchy, filtering, pagination, admin actions etc you get for
> free in the admin in my alternative view.
>
> Is this possible? How do I reuse most of the existing admin code to
> achieve this?
>
>
> --
> 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.



Question on the user auth model

2011-08-24 Thread raj
I'm reading the django docs, and I come across the following:

from django.contrib.auth.models import User

class UserProfile(models.Model):
# This field is required.
user = models.OneToOneField(User)

# Other fields here
accepted_eula = models.BooleanField()
favorite_animal = models.CharField(max_length=20,
default="Dragons.")

But, I've also seen it done this way:

class UserProfile(User):
# Other fields here
accepted_eula = models.BooleanField()
favorite_animal = models.CharField(max_length=20,
default="Dragons.")

Are there any differences between the two ways?

Also, can someone explain to me the post_save concept?

def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User).
Would this function work with only the first UserProfile class above?
Or will it also work with the second UserProfile Class. 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: dynamic field display

2011-08-24 Thread Axel Bock
yaah, but that's the most … inconvenient. 

the data model allows for the user to customize the fields he wants to use, 
depending on his requirements. I could start small, but the problem _will_ come 
at some point, so I thought I asked beforehand. 

but thanks for the answer, I already started "small" and postponed the problem. 
we'll see when I get there ;)


greetings, 
axel.



Am 23.08.2011 um 19:22 schrieb Subhranath Chunder:

> Manipulating the form instance attributes at runtime in your view might be 
> possible by modifying some internal fields, but that leads to dirty code and 
> not-so-clean views.
> 
> You can rather use different django forms with different field definitions in 
> your view. This might be the cleanest.
> 
> You can also consider creating some generator function which can return you a 
> django form class on the fly, depending upon the form definition parameters 
> provided to the generator function during runtime. Obviously you need to be 
> careful with this, and consider the cons coming with it.
> 
> 
> On Tue, Aug 23, 2011 at 12:01 AM, Axel Bock  
> wrote:
> Hi group,
> 
> I have another question about Django forms. I designed a Form for a Model, 
> but now I want to remove fields depending on some user settings.
> Can I do that?
> 
> Lets assume the following:
> 
> class MyModel(models.Model):
>field1 = TextField(null=True, blank=True)
>field2 = Textfield(null=True, blank=True)
> 
> class MyModelform(forms.Form):
>field1 = TextField()
>fiels2 = TextField()
> 
> def viewform(request):
># some magic here :)
>return render_to_response(context_instance=RequestContext(request, 
> {'form':MyModelForm()}))
> 
> Now I want to disable field2 in the form on display, depending on the user 
> settings. Any suggestions?
> 
> Greetings & thanks,
> Axel.
> 
> --
> 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.
> 
> 
> 
> 
> -- 
> Thanks,
> Subhranath Chunder.
> www.subhranath.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.



Creating an alternative change_list view for a specific app/model, not extending or overriding

2011-08-24 Thread Thomas Weholt
I want to create a view looking and working just like the admin
change_list, but using my own template ( based on the admin
change_list template ) so that all the filtering you get from
specifiying filtering in your adminmodel still works in my new view. I
DO NOT want to extend or override the existing one but provide an
additional/alternative view to the existing change_list for a specific
app/model. I need to change how the elements in the change_list are
presented. I'm listing photos, and want a layout like googles image
search, not the table-based you get by default in the admin. I need to
do this as well in my alternative view. I want to use the
date-hierarchy, filtering, pagination, admin actions etc you get for
free in the admin in my alternative view.

Is this possible? How do I reuse most of the existing admin code to
achieve this?


-- 
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: Django Development environment

2011-08-24 Thread cihan okyay
2011/8/23 Stephen Jackson 

> I am new to the world of Django. I would like to hear from other django
> developers describe their dev environment (tools, os, editors, etc.).


OS: Mac OSX

Development: TextMate, VIM, virtualenv, pip, south

Deployment: Ubuntu, apache, nginx, fabric, postgresql, uwsgi

Third-party django applications: django-nose, sentry, django-extensions

version control: GIT


-- 
Cihan Okyay
http://okyay.org/blog/

-- 
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: Need Ideas On Data Migration

2011-08-24 Thread Yaşar Arabacı
Thanks, I am marking this thread as SOLVED :)
2011/8/24 Kayode Odeyemi 

> +1 to South
>
> Just started with it myself
>
>
> On Wed, Aug 24, 2011 at 1:25 PM, Rory Hart  wrote:
>
>> South[1] handles database migrations. both schema and data. It can be a
>> little tricky when first starting to use it but it is a powerful system.
>>
>> Otherwise you could alter the table yourself and copy the data using SQL
>> or the django-admin shell.
>>
>> [1] http://south.aeracode.org/
>>
>> --
>> Rory Hart
>> http://www.roryhart.net
>> http://www.relishment.com
>>
>>
>> 2011/8/24 Yaşar Arabacı 
>>
>>> Hi,
>>>
>>> I have a model with a char field. All data saved in database in that
>>> field is a valid slug. Now I want to add this model a slug field, and copy
>>> all data from char fields to slug fields like so:
>>>
>>> Table before change:
>>>
>>> text = thisisavalidslug(char field)
>>>
>>> Table after change:
>>>
>>> text=thisisavalidslug(char field)
>>> slug=thisisavalidslug(slug field)
>>>
>>> Then later, I will change all char field manually to be more human
>>> readable with non-ascii letters and spaces. I just have like 10 items.
>>> --
>>> http://yasar.serveblog.net/
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
>
>
>  --
> 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.
>



-- 
http://yasar.serveblog.net/

-- 
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: Need Ideas On Data Migration

2011-08-24 Thread Kayode Odeyemi
+1 to South

Just started with it myself

On Wed, Aug 24, 2011 at 1:25 PM, Rory Hart  wrote:

> South[1] handles database migrations. both schema and data. It can be a
> little tricky when first starting to use it but it is a powerful system.
>
> Otherwise you could alter the table yourself and copy the data using SQL or
> the django-admin shell.
>
> [1] http://south.aeracode.org/
>
> --
> Rory Hart
> http://www.roryhart.net
> http://www.relishment.com
>
>
> 2011/8/24 Yaşar Arabacı 
>
>> Hi,
>>
>> I have a model with a char field. All data saved in database in that field
>> is a valid slug. Now I want to add this model a slug field, and copy all
>> data from char fields to slug fields like so:
>>
>> Table before change:
>>
>> text = thisisavalidslug(char field)
>>
>> Table after change:
>>
>> text=thisisavalidslug(char field)
>> slug=thisisavalidslug(slug field)
>>
>> Then later, I will change all char field manually to be more human
>> readable with non-ascii letters and spaces. I just have like 10 items.
>> --
>> http://yasar.serveblog.net/
>>
>>  --
>> 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.
>



-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

-- 
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: saving several models with one save() call

2011-08-24 Thread Kayode Odeyemi
Dmitry, I understand what you are trying to do clearly, coming from a Java
background myself.

But this is Python. Do it the Python way.

On Wed, Aug 24, 2011 at 6:33 PM, ernando  wrote:

> Hi Tom & Tundebabzy,
>
> I understood your idea & approach. But as I've mentioned - I receive
> the model from the 3rd party service & want to save it. As I have
> experience with Hibernate - it provides such features. That's why I'm
> a little bit frustrated with python approach.
>
> BR,
> Dmitry
>
> On Aug 24, 6:39 pm, Tundebabzy  wrote:
> > On Aug 24, 3:36 pm, Tom Evans  wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > On Tue, Aug 23, 2011 at 11:28 PM, ernando 
> wrote:
> > > > Hi all,
> >
> > > > maybe it's newbie question but I wasn't able to find clear answer/
> > > > solution on it.
> >
> > > > For example, we have the followingmodels:
> >
> > > > class A(models.Model):
> > > >id =models.AutoField(primary_key=True)
> > > >title =models.CharField(max_length=30)
> >
> > > > class B(models.Model):
> > > >id =models.AutoField(primary_key=True)
> > > >title =models.CharField(max_length=30)
> > > >aItems =models.OneToOneField(A)
> >
> > > > And try tosavethem in the following way:
> >
> > > > a = A(title="123")
> > > > b = B(title="333", aItems = a)
> > > > b.save()
> >
> > > > This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> > > > a default value")
> > > > if I firstlysavea object - everything goes smoothly. So, the
> > > > question is - should we alwayssaveall related objects manually?
> > > > According to django docs we have to create object at first. But
> that's
> > > > now always convenient - e.g. I receive full model from the 3rd part
> > > > service and want tosaveit into DB withonecalland not do it for
> > > > each item.
> >
> > > > Regards,
> > > > Dmitry
> >
> > > Only objects that exist in the database can be related to each other.
> > > If you have a function which accepts an model instance, it should make
> > > it clear that it is an error to pass it an object that does not exist
> > > in the database. You really should not be overridingsave() tosave
> > > related objects that do not exist in the database.
> >
> > > Mostly these kind of problems go away if you start using the create
> > > and get_or_create helpers on the model's manager, eg I would never
> > > have this in my code:
> >
> > > a = A(title="123")
> > > b = B(title="333", aItems = a)
> > > b.save()
> >
> > > it would look like this:
> >
> > > a, created = A.objects.get_or_create(title='123')
> > > b = B.objects.create(title='333', aitems=a)
> >
> > > Cheers
> >
> > > Tom
> >
> > +1
>
> --
> 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.
>
>


-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

-- 
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: saving several models with one save() call

2011-08-24 Thread ernando
Hi Tom & Tundebabzy,

I understood your idea & approach. But as I've mentioned - I receive
the model from the 3rd party service & want to save it. As I have
experience with Hibernate - it provides such features. That's why I'm
a little bit frustrated with python approach.

BR,
Dmitry

On Aug 24, 6:39 pm, Tundebabzy  wrote:
> On Aug 24, 3:36 pm, Tom Evans  wrote:
>
>
>
>
>
>
>
>
>
> > On Tue, Aug 23, 2011 at 11:28 PM, ernando  wrote:
> > > Hi all,
>
> > > maybe it's newbie question but I wasn't able to find clear answer/
> > > solution on it.
>
> > > For example, we have the followingmodels:
>
> > > class A(models.Model):
> > >    id =models.AutoField(primary_key=True)
> > >    title =models.CharField(max_length=30)
>
> > > class B(models.Model):
> > >    id =models.AutoField(primary_key=True)
> > >    title =models.CharField(max_length=30)
> > >    aItems =models.OneToOneField(A)
>
> > > And try tosavethem in the following way:
>
> > > a = A(title="123")
> > > b = B(title="333", aItems = a)
> > > b.save()
>
> > > This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> > > a default value")
> > > if I firstlysavea object - everything goes smoothly. So, the
> > > question is - should we alwayssaveall related objects manually?
> > > According to django docs we have to create object at first. But that's
> > > now always convenient - e.g. I receive full model from the 3rd part
> > > service and want tosaveit into DB withonecalland not do it for
> > > each item.
>
> > > Regards,
> > > Dmitry
>
> > Only objects that exist in the database can be related to each other.
> > If you have a function which accepts an model instance, it should make
> > it clear that it is an error to pass it an object that does not exist
> > in the database. You really should not be overridingsave() tosave
> > related objects that do not exist in the database.
>
> > Mostly these kind of problems go away if you start using the create
> > and get_or_create helpers on the model's manager, eg I would never
> > have this in my code:
>
> > a = A(title="123")
> > b = B(title="333", aItems = a)
> > b.save()
>
> > it would look like this:
>
> > a, created = A.objects.get_or_create(title='123')
> > b = B.objects.create(title='333', aitems=a)
>
> > Cheers
>
> > Tom
>
> +1

-- 
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: Drag and drop functionality?

2011-08-24 Thread glenn hafstrom
Hi Reinout

Thanks for your input.
I've googled a lot but I haven't found anything where I can drag from
another application to my django-site

Regards
glenn



On 24 Aug, 13:30, Reinout van Rees  wrote:
> On 24-08-11 13:19, glenn hafstrom wrote:
>
> > I'm new to this and I have just started with django.
> > I would like to have some kind of container for example I would like
> > to drag and drop a webaddress
> > to the container and then save them in my django application.
> > Is there any Javscript or anything else that I can use to handle
> > this?
>
> Best way is to do it in two steps:
>
> - First make a regular django form with one input field for the url and
> a submit button. Get that working.
>
> - Second step: google for some javascript that handles it. "jquery ui"
> has some drag/drop support, but I don't know if that also works for
> items dragged from outside the browser window.
>
> But get step 1 working first. Step 2 will need that functionality in
> place to be able to do something :-)
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"

-- 
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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Tom Evans
On Mon, Aug 22, 2011 at 11:37 PM, Jim  wrote:
> Hello folks,
> This probably has been discussed many times, but I still can't find any
> solution yet. Basically, it turns out that python can load MySQLdb just
> fine, but Apache can't load MySQLdb from the wsgi script.
> I am using python2.7 in a virtual environment created by virtualenv. Here is
> the error info extracted from the Apache error log. To make the lines
> shorter, I deleted all the time tags in the brackets.
> Any ideas how to fix it?
> [] mod_wsgi (pid=3136): Target WSGI script
> '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi' cannot be loaded
> as Python module.
> [] mod_wsgi (pid=3136): Exception occurred processing WSGI script
> '/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi'.
> [] Traceback (most recent call last):
> []   File "/Users/jianbao/projects/tao.com/mysite/apache/django.wsgi", line
> 56, in 
> []     import MySQLdb
> []   File
> "/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/MySQLdb/__init__.py",
> line 19, in 
> []     import _mysql
> [] ImportError:
> dlopen(/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/_mysql.so,
> 2): Library not loaded: libmysqlclient.18.dylib
> []   Referenced from:
> /Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/_mysql.so
> []   Reason: image not found
>

Are mysql, python and python-mysql all compiled correctly for the same
architecture? IE all 32 bit or all 64 bit.

ISTR that this can be a problem on OS X, but I'm not an OS X user...

http://stackoverflow.com/questions/1969222/mysql-python-1-2-3-and-os-x-10-5-64-or-32-bit

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: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 24-08-11 17:57, Jianbao Tao wrote:

Now './manage.py syncdb' can run through with no problems. However, it
doesn't create the database 'test.sqlite', which means the models in the
app, books, are still installed in the default database.



That's in the django docs: syncdb only managed the main default database 
by default. You'll have to call syncdb on the second database separately.


Often the second database is an existing one that django shouldn't 
touch, that's why the default is that way.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Reinout van Rees

On 24-08-11 17:12, Jianbao Tao wrote:

Thank you, Reinout.

I don't know which version of python mod_wsgi uses.


Look in /etc/apache2/mods-enabled/wsgi.load (that's on ubuntu, your 
mod_wsgi config file might be somewhere else. On one of my older servers 
it contains:


LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so-2.5

Which means it is a python2.5 mod_wsgi. In ubuntu's case, as it is in 
/usr/lib, it means that it uses the system python2.5.


Your python dirs look like this:


/usr/local/bin/python

/usr/local/bin/python-32

/usr/local/bin/python2.7


That's all locally compiled by hand. There's no way I can tell you which 
one of 'em is used by apache :-) But probably what you'd get when 
calling "python2.7" if your wsgi config indicates it is for 2.7.


You got your wsgi script to print the environment



'PATH':
'/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/Users/jianbao/shlib:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/usr/X11/bin:/Users/jianbao/pylib:/usr/local/mysql/bin',


Wow! That's a lot of custom stuff in there, including multiple python 
paths. To me, it looks like pure luck if it is able to find the correct 
mysql in there :-)


But what I was looking for: virtualenv puts the bin directory of the 
virtualenv in the path. I don't see anything that looks like a 
virtualenv dir in there, unless it is the /Users/jianbao/pylib at the end.


I personally don't know how wsgi+virtualenv works together (I use 
buildout normally). so you'll have to ask around for that.





Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Problems on using multiple databases

2011-08-24 Thread Jianbao Tao
Thank you, Reinout.

I changed the definition of 'allow_syncdb' to the following:

def allow_syncdb(self, db, model):
# db is a string of database name.
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
if dbName == db:
return True
else:
return None


Now './manage.py syncdb' can run through with no problems. However, it
doesn't create the database 'test.sqlite', which means the models in the
app, books, are still installed in the default database.

Also, I am using django v1.3.

In addition, about the *two* things you mentioned, how can I test for that?
It seems all the functions defined in the class DBRouter are called
internally by django. I don't know how to make django print something so
that I know what's going on when django calls those function.

Again, thank you very much.


On Wed, Aug 24, 2011 at 2:15 AM, Reinout van Rees wrote:

> On 23-08-11 01:31, Jim wrote:
>
>> def allow_syncdb(self, db, model):
>> # db is a string of database name.
>> label = model._meta.app_label
>> if label == 'books':
>> dbName = 'test'
>> else:
>> dbName = None
>> return dbName == db
>>
>
> I'd do the "if" part as follows:
>
>if label == 'books':
>if db == 'test':
>return True
>return False
>if db == 'test':
>return False
>return None  # None means 'no opinion'.
>
> iirc allow_syncdb() ought to return True/False to indicate whether a
> certain model should be synced to a certain database. So you need to make
> sure *two* things:
>
> - Your special models only end up in your special database and not in
> another.
>
> - Other models (like the django_content_type table that gives you
> problems!) should not end up in your special deatabase.
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> 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: saving several models with one save() call

2011-08-24 Thread Tundebabzy


On Aug 24, 3:36 pm, Tom Evans  wrote:
> On Tue, Aug 23, 2011 at 11:28 PM, ernando  wrote:
> > Hi all,
>
> > maybe it's newbie question but I wasn't able to find clear answer/
> > solution on it.
>
> > For example, we have the following models:
>
> > class A(models.Model):
> >    id = models.AutoField(primary_key=True)
> >    title = models.CharField(max_length=30)
>
> > class B(models.Model):
> >    id = models.AutoField(primary_key=True)
> >    title = models.CharField(max_length=30)
> >    aItems = models.OneToOneField(A)
>
> > And try to save them in the following way:
>
> > a = A(title="123")
> > b = B(title="333", aItems = a)
> > b.save()
>
> > This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> > a default value")
> > if I firstly save a object - everything goes smoothly. So, the
> > question is - should we always save all related objects manually?
> > According to django docs we have to create object at first. But that's
> > now always convenient - e.g. I receive full model from the 3rd part
> > service and want to save it into DB with one call and not do it for
> > each item.
>
> > Regards,
> > Dmitry
>
> Only objects that exist in the database can be related to each other.
> If you have a function which accepts an model instance, it should make
> it clear that it is an error to pass it an object that does not exist
> in the database. You really should not be overriding save() to save
> related objects that do not exist in the database.
>
> Mostly these kind of problems go away if you start using the create
> and get_or_create helpers on the model's manager, eg I would never
> have this in my code:
>
> a = A(title="123")
> b = B(title="333", aItems = a)
> b.save()
>
> it would look like this:
>
> a, created = A.objects.get_or_create(title='123')
> b = B.objects.create(title='333', aitems=a)
>
> Cheers
>
> Tom

+1

-- 
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 is Django?

2011-08-24 Thread Derek
http://www.djangobook.com/en/2.0/chapter01/
discusses what a web framework is, and why/how it might offer you more
productivity just using "raw" Python (bearing in mind that most of the
time, apart from the HTML templates, you *will* be using Python
anyway).

You cannot "see" a sample app because apps are meant to be used as
part of a project; if that is what you meant, then look at
http://www.djangosites.org/ for example of such projects.

http://pinaxproject.com/ is a good example of a project that
integrates multiple Django apps and is, itself, designed to be
customized further.  If you are building websites that fit into the
domain space that it covers, you'd get a boost in productivity from
not re-inventing some wheels.

On Aug 23, 2:01 pm, Julian  wrote:
> Is there any document available that describes WHAT Django is? I am
> not looking for an installation guide, neither for tutorial, nor for
> "Django is a high-level Python Web framework". But: What does this
> framework include? What is it used for? How does it increase
> productivity? Why shouldn't I use directly Python to create web apps/
> pages? How could a sample app look like (without giving source code)?
>
> Such explanations would be extremely helpful and maybe even worth to
> be linked intohttps://www.djangoproject.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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Jianbao Tao
Sorry, I pasted the 'python django.wsgi' output in a wrong place.



On Wed, Aug 24, 2011 at 9:12 AM, Jianbao Tao  wrote:

> Thank you, Reinout.
>
> I don't know which version of python mod_wsgi uses. Here is a list of
> python versions on my machine.
>
> /Library/Frameworks/Python.framework//Versions/2.7/bin/python
>
> /usr/bin/python2.5
>
> /usr/bin/python2.6
>
> /usr/bin/pythonw2.5
>
> /usr/bin/pythonw2.6
>
> /usr/local/bin/python
>
> /usr/local/bin/python-32
>
> /usr/local/bin/python2.7
>
> /usr/local/bin/python2.7-32
>
> /usr/local/bin/python3
>
> /usr/local/bin/python3-32
>
> /usr/local/bin/python3.2
>
> /usr/local/bin/python3.2-32
>
> /usr/local/bin/python3.2m
>
> /usr/local/bin/pythonw
>
> /usr/local/bin/pythonw-32
>
> /usr/local/bin/pythonw2.7
>
> /usr/local/bin/pythonw2.7-32
>
> /usr/local/bin/pythonw3
>
> /usr/local/bin/pythonw3-32
>
> /usr/local/bin/pythonw3.2
>
> /usr/local/bin/pythonw3.2-32
>
> As you can see, there is no /usr/bin/python. And '/usr/local/bin/python
> --version' gives Python 2.7.2., which is normally what I use.
>
> For your second suggestion, I don't know if apache can access mysql
> libraries. Can you tell me how to find out?
>
>
> On Wed, Aug 24, 2011 at 2:05 AM, Reinout van Rees wrote:
>
>> On 23-08-11 00:37, Jim wrote:
>>
>>> This probably has been discussed many times, but I still can't find any
>>> solution yet. Basically, it turns out that python can load MySQLdb just
>>> fine, but Apache can't load MySQLdb from the wsgi script.
>>>
>>>
>> - Does apache use the virtualenv's environment? And this is what I got
>> from 'print os.environ' in the .wsgi file.
>>
> >$ python django.wsgi
> {'TEXPATH': '/usr/local/texlive/2010/texmf-dist/tex/latex',
> 'PROMPT_COMMAND': 'echo -ne "\\033]0;${tabtit}\\007"', 'IDL_DIR':
> '/Applications/itt/idl/idl81', 'LOGNAME': 'jianbao', 'USER': 'jianbao',
> 'ITT_DIR': '/Applications/itt', 'HOME': '/Users/jianbao', 'PATH':
> '/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/Users/jianbao/shlib:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/usr/X11/bin:/Users/jianbao/pylib:/usr/local/mysql/bin',
> 'PS1': '\\n\\e[0;34m$PWD\\e[m\\n>$ ', 'DISPLAY':
> '/tmp/launch-YVSOek/org.x:0', 'TERM_PROGRAM': 'iTerm.app', 'LANG':
> 'en_US.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'COLORFGBG': '0;15',
> 'SHLVL': '1', 'ITERM_SESSION_ID': 'w0t0p0', '_':
> '/Library/Frameworks/Python.framework/Versions/2.7/bin/python', 'MANPATH':
> '/opt/local/share/man:', 'ARCHFLAGS': '-arch i386 -arch x86_64',
> 'SSH_AUTH_SOCK': '/tmp/launch-EXjeyZ/Listeners', 'IDL_STARTUP':
> '$HOME/idllib/idl_startup.pro', 'DYLD_LIBRARY_PATH':
> '/usr/local/mysql/lib:', 'Apple_PubSub_Socket_Render':
> '/tmp/launch-67EotD/Render', 'TMPDIR':
> '/var/folders/Yb/YbFx+MU1HhWVkmSHSxe4fk+++TI/-Tmp-/', 'LSCOLORS':
> 'ExFxCxDxBxegedabagacad', 'IDL_DLM_PATH':
> ':+/Users/jianbao/idllib/DLM/idl_geopack_75:+/Users/jianbao/idllib/spice/icy/lib',
> 'PYTHONSTARTUP': '/Users/jianbao/pylib/startup.py', 'IDL_PATH':
> '', 'OLDPWD': '/Users/jianbao/projects/tao.com/djangoSite/bin',
> 'CLICOLOR': '1', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'PWD':
> '/Users/jianbao/projects/tao.com/djangoSite/apache', 'tabtit':
> 'djangoSite', 'COMMAND_MODE': 'unix2003'}
>
> I don't see any clue, though.
>
> Thank you very much.
>
>
>
>>
>> - Mod_wsgi: does that use the correct python version? mod_wsgi normally
>> uses /usr/bin/python (python 2.5 or 3.2 whatever) and you might have used
>> /usr/bin/python2.7.
>>
>> - Can the apache process find the mysql libraries? Are the environement
>> variables different? Try printing "os.environ" from your .wsgi script for
>> instance.
>>
>> Just some brainstorming.
>>
>>
>> Reinout
>>
>> --
>> Reinout van Reeshttp://reinout.vanrees.org/
>> rein...@vanrees.org 
>> http://www.nelen-schuurmans.**nl/
>> "If you're not sure what to do, make something. -- Paul Graham"
>>
>> --
>> 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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Jianbao Tao
Thank you, Reinout.

I don't know which version of python mod_wsgi uses. Here is a list of python
versions on my machine.

/Library/Frameworks/Python.framework//Versions/2.7/bin/python

/usr/bin/python2.5

/usr/bin/python2.6

/usr/bin/pythonw2.5

/usr/bin/pythonw2.6

/usr/local/bin/python

/usr/local/bin/python-32

/usr/local/bin/python2.7

/usr/local/bin/python2.7-32

/usr/local/bin/python3

/usr/local/bin/python3-32

/usr/local/bin/python3.2

/usr/local/bin/python3.2-32

/usr/local/bin/python3.2m

/usr/local/bin/pythonw

/usr/local/bin/pythonw-32

/usr/local/bin/pythonw2.7

/usr/local/bin/pythonw2.7-32

/usr/local/bin/pythonw3

/usr/local/bin/pythonw3-32

/usr/local/bin/pythonw3.2

/usr/local/bin/pythonw3.2-32

As you can see, there is no /usr/bin/python. And '/usr/local/bin/python
--version' gives Python 2.7.2., which is normally what I use.

For your second suggestion, I don't know if apache can access mysql
libraries. Can you tell me how to find out?


On Wed, Aug 24, 2011 at 2:05 AM, Reinout van Rees wrote:

> On 23-08-11 00:37, Jim wrote:
>
>> This probably has been discussed many times, but I still can't find any
>> solution yet. Basically, it turns out that python can load MySQLdb just
>> fine, but Apache can't load MySQLdb from the wsgi script.
>>
>>
> - Does apache use the virtualenv's environment? And this is what I got from
> 'print os.environ' in the .wsgi file.
>
>$ python django.wsgi
{'TEXPATH': '/usr/local/texlive/2010/texmf-dist/tex/latex',
'PROMPT_COMMAND': 'echo -ne "\\033]0;${tabtit}\\007"', 'IDL_DIR':
'/Applications/itt/idl/idl81', 'LOGNAME': 'jianbao', 'USER': 'jianbao',
'ITT_DIR': '/Applications/itt', 'HOME': '/Users/jianbao', 'PATH':
'/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/Users/jianbao/shlib:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/usr/X11/bin:/Users/jianbao/pylib:/usr/local/mysql/bin',
'PS1': '\\n\\e[0;34m$PWD\\e[m\\n>$ ', 'DISPLAY':
'/tmp/launch-YVSOek/org.x:0', 'TERM_PROGRAM': 'iTerm.app', 'LANG':
'en_US.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'COLORFGBG': '0;15',
'SHLVL': '1', 'ITERM_SESSION_ID': 'w0t0p0', '_':
'/Library/Frameworks/Python.framework/Versions/2.7/bin/python', 'MANPATH':
'/opt/local/share/man:', 'ARCHFLAGS': '-arch i386 -arch x86_64',
'SSH_AUTH_SOCK': '/tmp/launch-EXjeyZ/Listeners', 'IDL_STARTUP':
'$HOME/idllib/idl_startup.pro', 'DYLD_LIBRARY_PATH':
'/usr/local/mysql/lib:', 'Apple_PubSub_Socket_Render':
'/tmp/launch-67EotD/Render', 'TMPDIR':
'/var/folders/Yb/YbFx+MU1HhWVkmSHSxe4fk+++TI/-Tmp-/', 'LSCOLORS':
'ExFxCxDxBxegedabagacad', 'IDL_DLM_PATH':
':+/Users/jianbao/idllib/DLM/idl_geopack_75:+/Users/jianbao/idllib/spice/icy/lib',
'PYTHONSTARTUP': '/Users/jianbao/pylib/startup.py', 'IDL_PATH':
'', 'OLDPWD': '/Users/jianbao/projects/tao.com/djangoSite/bin',
'CLICOLOR': '1', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'PWD':
'/Users/jianbao/projects/tao.com/djangoSite/apache', 'tabtit': 'djangoSite',
'COMMAND_MODE': 'unix2003'}

I don't see any clue, though.

Thank you very much.



>
> - Mod_wsgi: does that use the correct python version? mod_wsgi normally
> uses /usr/bin/python (python 2.5 or 3.2 whatever) and you might have used
> /usr/bin/python2.7.
>
> - Can the apache process find the mysql libraries? Are the environement
> variables different? Try printing "os.environ" from your .wsgi script for
> instance.
>
> Just some brainstorming.
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
> --
> 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: m2m assignments lost when saving in admin but not shell

2011-08-24 Thread Shawn Milochik

In case anyone's interested:

I still don't know what the problem was, but I solved it by just doing a 
delay call to a Celery task, so it happens asynchronously.


I was already using Celery/RabbitMQ, and the functionality was one of 
the things I wanted to make async anyway.


--
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: saving several models with one save() call

2011-08-24 Thread Tom Evans
On Tue, Aug 23, 2011 at 11:28 PM, ernando  wrote:
> Hi all,
>
> maybe it's newbie question but I wasn't able to find clear answer/
> solution on it.
>
> For example, we have the following models:
>
> class A(models.Model):
>    id = models.AutoField(primary_key=True)
>    title = models.CharField(max_length=30)
>
> class B(models.Model):
>    id = models.AutoField(primary_key=True)
>    title = models.CharField(max_length=30)
>    aItems = models.OneToOneField(A)
>
> And try to save them in the following way:
>
> a = A(title="123")
> b = B(title="333", aItems = a)
> b.save()
>
> This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> a default value")
> if I firstly save a object - everything goes smoothly. So, the
> question is - should we always save all related objects manually?
> According to django docs we have to create object at first. But that's
> now always convenient - e.g. I receive full model from the 3rd part
> service and want to save it into DB with one call and not do it for
> each item.
>
> Regards,
> Dmitry
>

Only objects that exist in the database can be related to each other.
If you have a function which accepts an model instance, it should make
it clear that it is an error to pass it an object that does not exist
in the database. You really should not be overriding save() to save
related objects that do not exist in the database.

Mostly these kind of problems go away if you start using the create
and get_or_create helpers on the model's manager, eg I would never
have this in my code:

a = A(title="123")
b = B(title="333", aItems = a)
b.save()

it would look like this:

a, created = A.objects.get_or_create(title='123')
b = B.objects.create(title='333', aitems=a)

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: urlencode in template gives unexpected result (for me :-)

2011-08-24 Thread Tom Evans
On Wed, Aug 24, 2011 at 2:50 PM, Michel30  wrote:
>
>
> On Aug 24, 3:22 pm, Tom Evans  wrote:
>> On Wed, Aug 24, 2011 at 1:47 PM, Michel30  wrote:
>> > Hi all,
>>
>> > I have written an application using Django 1.3 , apache2 and a mysql
>> > db.
>> > I'm using the db to store filepaths and filenames for legacy purposes
>> > while serving them to users with apache.
>>
>> > Now mysql is using latin-1 (with the filenames most likely stored in
>> > CP-1252) while Django uses utf-8.
>>
>> That is not going to fly. You will likely need to ensure you have a
>> consistent character encoding across your website, database and file
>> system.
>>
>> Cheers
>>
>> Tom
>
> Tom,
>
> that looks like it would be best, yes (this is my first exposure to
> encoding problems)
>
> I cannot change the filesystem or mysql encoding since the legacy
> application is still using it. I assumed that with utf-8 I would be
> good as it covers all(?) and I understood mysql translates itself from
> latin-1 to utf-8 and vice versa.
>
> As far as I can see this only hurts my hyperlinks, more specifically
> only file.filename so wouldn't translating only these work?
>

Trusting mysql to DTRT with character encoding does not work well in
my experience. For starters, if your database is latin1, there is a
huge range of UTF-8 characters that cannot be encode to latin1. If
your website is presented in UTF-8, as is default for Django, then
input submitted by your users will be in UTF-8 as well, and quite
easily cannot be stored in the database. Many browsers will submit
\u2019 - ’ - instead of a simple ' character, which will not fit in
latin1.

When it comes to serving your files, Apache url-decodes your request,
it doesn't assume anything about the character encoding of the bytes
after that and will simply open that file system location path. If
your files are stored in the file system with latin1 names, that means
the requested file name must be encoded in latin1. So sure, you could
latin1 encode each filename, and then urlencode the result.

You are opening yourself up for a world of pain by not using
consistent character encodings. It will hurt you eventually.

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: saving several models with one save() call

2011-08-24 Thread ernando
Hi Babatunde,

Thanks, I see your point. I know about this solution but thought that
I've missed anything and there is a common approach how to do it
automatically. So, will start working on save() method overriding.

Regards,
Dmitry

On Aug 24, 12:36 pm, Babatunde Akinyanmi  wrote:
> You will need tosavethe A object first. What you can do is override
> thesavemethod for B model. In the function, check for which argument
> in *args is an A object. When found,callthe super method for A's
> defaultsavemethod thencallthe super method for B's defaultsave
> method. That should work just fine.
> I haven't tried it but I believe it would work. I'm an accountant and
> there's a lot of work on my table right now but I could find time
> during break to try algorithm and tell you if it works
>
> On 8/23/11, ernando  wrote:
>
>
>
>
>
>
>
>
>
> > Hi all,
>
> > maybe it's newbie question but I wasn't able to find clear answer/
> > solution on it.
>
> > For example, we have the followingmodels:
>
> > class A(models.Model):
> >     id =models.AutoField(primary_key=True)
> >     title =models.CharField(max_length=30)
>
> > class B(models.Model):
> >     id =models.AutoField(primary_key=True)
> >     title =models.CharField(max_length=30)
> >     aItems =models.OneToOneField(A)
>
> > And try tosavethem in the following way:
>
> > a = A(title="123")
> > b = B(title="333", aItems = a)
> > b.save()
>
> > This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> > a default value")
> > if I firstlysavea object - everything goes smoothly. So, the
> > question is - should we alwayssaveall related objects manually?
> > According to django docs we have to create object at first. But that's
> > now always convenient - e.g. I receive full model from the 3rd part
> > service and want tosaveit into DB withonecalland not do it for
> > each item.
>
> > Regards,
> > Dmitry
>
> > --
> > 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.
>
> --
> Sent from my mobile device

-- 
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: urlencode in template gives unexpected result (for me :-)

2011-08-24 Thread Michel30


On Aug 24, 3:22 pm, Tom Evans  wrote:
> On Wed, Aug 24, 2011 at 1:47 PM, Michel30  wrote:
> > Hi all,
>
> > I have written an application using Django 1.3 , apache2 and a mysql
> > db.
> > I'm using the db to store filepaths and filenames for legacy purposes
> > while serving them to users with apache.
>
> > Now mysql is using latin-1 (with the filenames most likely stored in
> > CP-1252) while Django uses utf-8.
>
> That is not going to fly. You will likely need to ensure you have a
> consistent character encoding across your website, database and file
> system.
>
> Cheers
>
> Tom

Tom,

that looks like it would be best, yes (this is my first exposure to
encoding problems)

I cannot change the filesystem or mysql encoding since the legacy
application is still using it. I assumed that with utf-8 I would be
good as it covers all(?) and I understood mysql translates itself from
latin-1 to utf-8 and vice versa.

As far as I can see this only hurts my hyperlinks, more specifically
only file.filename so wouldn't translating only these work?

-- 
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: query concerning three tables

2011-08-24 Thread Tom Evans
On Wed, Aug 24, 2011 at 2:12 PM, john  wrote:
> i had three tables,
> trademarks, publication, and entry
> trademarks has a foreign key to publication, and publication has a
> foreign key to entry, and entry has a field called published_date,
> which i am intrested in..
> how should i go about such using filters or similar..
> when i am writing something like this...
> tm_queryset =
> Trademarks.objects.all().filter(created_by__id__exact=76).
>
> i have tried this.. but guess its too off the mark..
> t   =
> Trademark.objects.all().filter(created_by__id__exact=curr_id).select_related('pub_date','publication_id').filter(pub_date__range=(start_date,end_date),
> status__exact=status_code, publication_id__exact=pubid)
>

You need to explain more clearly what information you want to
retrieve, what you have tried, what happened, why that isn't what you
want.

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: urlencode in template gives unexpected result (for me :-)

2011-08-24 Thread Tom Evans
On Wed, Aug 24, 2011 at 1:47 PM, Michel30  wrote:
> Hi all,
>
> I have written an application using Django 1.3 , apache2 and a mysql
> db.
> I'm using the db to store filepaths and filenames for legacy purposes
> while serving them to users with apache.
>
> Now mysql is using latin-1 (with the filenames most likely stored in
> CP-1252) while Django uses utf-8.
>

That is not going to fly. You will likely need to ensure you have a
consistent character encoding across your website, database and file
system.

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.



query concerning three tables

2011-08-24 Thread john
i had three tables,
trademarks, publication, and entry
trademarks has a foreign key to publication, and publication has a
foreign key to entry, and entry has a field called published_date,
which i am intrested in..
how should i go about such using filters or similar..
when i am writing something like this...
tm_queryset =
Trademarks.objects.all().filter(created_by__id__exact=76).

i have tried this.. but guess its too off the mark..
t   =
Trademark.objects.all().filter(created_by__id__exact=curr_id).select_related('pub_date','publication_id').filter(pub_date__range=(start_date,end_date),
status__exact=status_code, publication_id__exact=pubid)

-- 
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.



urlencode in template gives unexpected result (for me :-)

2011-08-24 Thread Michel30
Hi all,

I have written an application using Django 1.3 , apache2 and a mysql
db.
I'm using the db to store filepaths and filenames for legacy purposes
while serving them to users with apache.

Now mysql is using latin-1 (with the filenames most likely stored in
CP-1252) while Django uses utf-8.

I generate the links to the files thusly in my template:
   {{ file.filename }}

This works until I have funky character, lets say File….pdf

Then my hyperlink reads:
File….pdf

While Apache throws a 404 with: NotFound /path/File….pdf

Obviously because it expects this link:
File….pdf

Any ideas how to fix this in the template?
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: Need Ideas On Data Migration

2011-08-24 Thread Rory Hart
South[1] handles database migrations. both schema and data. It can be a
little tricky when first starting to use it but it is a powerful system.

Otherwise you could alter the table yourself and copy the data using SQL or
the django-admin shell.

[1] http://south.aeracode.org/

-- 
Rory Hart
http://www.roryhart.net
http://www.relishment.com


2011/8/24 Yaşar Arabacı 

> Hi,
>
> I have a model with a char field. All data saved in database in that field
> is a valid slug. Now I want to add this model a slug field, and copy all
> data from char fields to slug fields like so:
>
> Table before change:
>
> text = thisisavalidslug(char field)
>
> Table after change:
>
> text=thisisavalidslug(char field)
> slug=thisisavalidslug(slug field)
>
> Then later, I will change all char field manually to be more human readable
> with non-ascii letters and spaces. I just have like 10 items.
> --
> http://yasar.serveblog.net/
>
>  --
> 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: message mark_safe and redirect results in message still showiing with encoded tags

2011-08-24 Thread Leon van der Ree
Great tip!

thanks for this hint, I decided to (mis-)use extra_tags for this
purpose!

I have now implemented the following:

try:
# build a safe message
raise InvalidUserException(message=mark_safe('some safe
message'))
expect Exception e:
# test if content is safe, if so: flag message as safe
extra_tags = None
if isinstance(e.message, SafeData):
extra_tags = 'safe'
messages.error(request, e.message, extra_tags)


And now I can show the message in my template, with the help of an
extra template_tag

{% if messages %}

{% for message in messages %}
{{ message|test_safe_tag }}
{% endfor %}

{% endif %}


Where test_safe_tag is defined as:

@register.filter
def test_safe_tag(message):
"""test if the message contains safe in the extra_tag"""
if message.extra_tags == "safe":
message.message = mark_safe(message.message)
return message

it's not perfect: it generates an extra class in my html (safe), and I
need to perform these extra steps (of performing the testing if it is
safe, to set the extra flag, and when presenting I have to test for
this flag again as well), but at least it is allowed when marked safe!


On 23 aug, 16:48, Andy McKay  wrote:
> On 2011-08-23, at 1:08 AM, Leon van der Ree wrote:
>
> > that explains why I experience this issue. However doesn't it suppose
> > to work like this; Why should a safe string become unsafe again after
> > deserialisation? I understand this is a current limitation of the
> > serialisation process, but this is not exactly what you would expect,
> > is it. So in my eyes this is still a bug.
>
> Nothing advertises it would work this way, so its a feature request.
>
> > Are there any known workarounds?
>
> You could store more than a string in the message I bet, for example 
> {'msg':'hello', 'safe':True} and then cope with it when you deserialize.
> --
>   Andy McKay
>   a...@clearwind.ca
>   twitter: @andymckay

-- 
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.



Need Ideas On Data Migration

2011-08-24 Thread Yaşar Arabacı
Hi,

I have a model with a char field. All data saved in database in that field
is a valid slug. Now I want to add this model a slug field, and copy all
data from char fields to slug fields like so:

Table before change:

text = thisisavalidslug(char field)

Table after change:

text=thisisavalidslug(char field)
slug=thisisavalidslug(slug field)

Then later, I will change all char field manually to be more human readable
with non-ascii letters and spaces. I just have like 10 items.
-- 
http://yasar.serveblog.net/

-- 
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: Drag and drop functionality?

2011-08-24 Thread Reinout van Rees

On 24-08-11 13:19, glenn hafstrom wrote:

I'm new to this and I have just started with django.
I would like to have some kind of container for example I would like
to drag and drop a webaddress
to the container and then save them in my django application.
Is there any Javscript or anything else that I can use to handle
this?


Best way is to do it in two steps:

- First make a regular django form with one input field for the url and 
a submit button. Get that working.


- Second step: google for some javascript that handles it. "jquery ui" 
has some drag/drop support, but I don't know if that also works for 
items dragged from outside the browser window.



But get step 1 working first. Step 2 will need that functionality in 
place to be able to do something :-)



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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.



Drag and drop functionality?

2011-08-24 Thread glenn hafstrom
Hi
I'm new to this and I have just started with django.
I would like to have some kind of container for example I would like
to drag and drop a webaddress
to the container and then save them in my django application.
Is there any Javscript or anything else that I can use to handle
this?

Regards
gh

-- 
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: Upload Progress bar

2011-08-24 Thread Cal Leeming [Simplicity Media Ltd]
A simple google search brought back the answers you needed:

http://www.google.co.uk/search?sourceid=chrome=UTF-8=upload+progress+django

Please refer to the following document before asking for help from the list:

https://code.djangoproject.com/wiki/UsingTheMailingList

Cal


On Wed, Aug 24, 2011 at 11:59 AM, Dhinesh Babu wrote:

> Hi Guys,
> I'm a newbie to this web framework of Django. As part of a project, I was
> asked to implement the following things
>
>- Upload Progress bar
>   - Showing the percentage uploaded
>   - Generally the files are very large
>- File being uploaded
>   - There will be tar balls being uploaded which have many
>   sub-directories within
>   - So need to show the user the file being uploaded (Donno if it’s
>   possible)
>
> Please help me on this. Thanks in advance. Mail me if any further details
> are needed.
>
>
> Cheers,
>
> Dhinesh
>
> --
> 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: Upload Progress bar

2011-08-24 Thread delegbede
Try django-uploadify. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Dhinesh Babu 
Sender: django-users@googlegroups.com
Date: Wed, 24 Aug 2011 16:29:33 
To: 
Reply-To: django-users@googlegroups.com
Subject: Upload Progress bar

Hi Guys,
I'm a newbie to this web framework of Django. As part of a project, I was
asked to implement the following things

   - Upload Progress bar
  - Showing the percentage uploaded
  - Generally the files are very large
   - File being uploaded
  - There will be tar balls being uploaded which have many
  sub-directories within
  - So need to show the user the file being uploaded (Donno if it’s
  possible)

Please help me on this. Thanks in advance. Mail me if any further details
are needed.


Cheers,

Dhinesh

-- 
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.



Upload Progress bar

2011-08-24 Thread Dhinesh Babu
Hi Guys,
I'm a newbie to this web framework of Django. As part of a project, I was
asked to implement the following things

   - Upload Progress bar
  - Showing the percentage uploaded
  - Generally the files are very large
   - File being uploaded
  - There will be tar balls being uploaded which have many
  sub-directories within
  - So need to show the user the file being uploaded (Donno if it’s
  possible)

Please help me on this. Thanks in advance. Mail me if any further details
are needed.


Cheers,

Dhinesh

-- 
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: saving several models with one save() call

2011-08-24 Thread Babatunde Akinyanmi
You will need to save the A object first. What you can do is override
the save method for B model. In the function, check for which argument
in *args is an A object. When found, call the super method for A's
default save method then call the super method for B's default save
method. That should work just fine.
I haven't tried it but I believe it would work. I'm an accountant and
there's a lot of work on my table right now but I could find time
during break to try algorithm and tell you if it works


On 8/23/11, ernando  wrote:
> Hi all,
>
> maybe it's newbie question but I wasn't able to find clear answer/
> solution on it.
>
> For example, we have the following models:
>
> class A(models.Model):
> id = models.AutoField(primary_key=True)
> title = models.CharField(max_length=30)
>
> class B(models.Model):
> id = models.AutoField(primary_key=True)
> title = models.CharField(max_length=30)
> aItems = models.OneToOneField(A)
>
> And try to save them in the following way:
>
> a = A(title="123")
> b = B(title="333", aItems = a)
> b.save()
>
> This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> a default value")
> if I firstly save a object - everything goes smoothly. So, the
> question is - should we always save all related objects manually?
> According to django docs we have to create object at first. But that's
> now always convenient - e.g. I receive full model from the 3rd part
> service and want to save it into DB with one call and not do it for
> each item.
>
> Regards,
> Dmitry
>
> --
> 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.
>
>

-- 
Sent from my mobile device

-- 
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: Admin staticfiles stubbornly hiding behind 404s

2011-08-24 Thread Reinout van Rees

On 24-08-11 11:32, Kevin Golding wrote:

Basically static files is just an easier way to copy the admin
css/js/etc. to the project specific directories rather than serving
them directly from the master location?


It is more. I mean, it doesn't just copy the admin css/js, but the 
css/js from ALL apps.


Every app you have can have a static/ subdirectory and put stuff in it, 
just like the templates/ directory. And a site that uses the application 
will automatically get the right js/css without having to grab the 
correct js/css by hand from five different locations!


What we have, as an example, is a basic "ui" application with basic 
templates and a couple of javascript libraries (jquery, jquery ui, etc) 
and basic css. A second app comes with javascript for rendering maps 
(openlayers + custom js). And we have a bunch of sites that use both 
these applications, all getting the right js/css out of the box.


Handy!


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Newbe DateTimeField Question

2011-08-24 Thread Tom Evans
On Sun, Aug 21, 2011 at 12:33 PM, Torsten  wrote:
> Hi
>
> I simply want the DateTime to be set to null.
>
> payed_at = models.DateTimeField(null=True)
>
> but always get this as an error:
>
> IntegrityError at /admin/invoice/invoice/add/
> invoice_invoice.payed_at may not be NULL
>
>
> Thanks for help.
>
> Torsten
>

IntegrityError comes from the database, so django was happy with
having payed_at=None, but your database wasn't. I suspect you added
null=True to your model after having run syncdb, and the database
table does not reflect the model.

Remember that syncdb does not modify tables that already exist, or
validate that they match their corresponding models.

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: Re: pydra

2011-08-24 Thread Henrik Genssen
yes, some of its features seem to be solved in celery, which I have used for a 
long time
I came across pydra because it claims to provide map/reduce features...

regards

Henrik

>reply to message:
>date: 24.08.2011 10:34:40
>from: "Tom Evans" 
>to: django-users@googlegroups.com
>subject: [] Re: pydra
>
>On Tue, Aug 23, 2011 at 11:44 PM, hinnack  wrote:
>> hi all,
>>
>> Anyone ever used pydra?
>> http://code.osuosl.org/projects/pydra/wiki
>>
>> could not find a thread on the list...
>>
>> Regards
>>
>> Henrik
>>
>
>Looks like a re-invention of celery/amqp. Think I'll stick with the original.
>
>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: Admin staticfiles stubbornly hiding behind 404s

2011-08-24 Thread Kevin Golding
On 24 August 2011 09:40, Reinout van Rees  wrote:
> On 23-08-11 13:25, Caomhin wrote:
>>
>> I confess, I'm lost!  I've just tried starting my first new site since
>> upgrading to Django 1.3 and the new staticfiles settings seem to be
>> taunting me.  I've tried a number of variations but every setting I
>> have returns a 404 for the admin interface css.  Here's what I have
>> just now:
>>
>> MEDIA_URL = 'media/'
>
> I'd put a slash in front of that, but that shouldn't be related to your
> admin css problem.

Well spotted, cheers

>> %python manage.py findstatic admin/css/dashboard.css
>> Found 'admin/css/dashboard.css' here:
>>   /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/
>> css/dashboard.css
>
> Yep, it finds it through the "django app"'s static/ directory.

Aah okay, this is definitely something I had missed.  With hindsight I
should have tried findstatic before I started adding to the search
paths and then I might have figured out that there was a default
static folder that gets checked.  There's a chance I was over
confident about that one :-)  It makes sense though.

>> So I'm fairly happy that django is finding these files in a sane an
>> happy manner, and the failure on the final one gives me a sense of
>> reassurance that the paths are all making sense, but still the
>> templates are generating  and the stylesheets are not found.
>
> When are they not found? Both in development and on the server? Or only on
> the server?

Well as it's a totally new project I'm happily doing the early stages
of development on the server itself, my set-up means it's barely more
effort than using the development server at this stage of the process
and it saves the hassle of moving it to the server afterwards.  A lazy
shortcut in other words.

> On the server, you need to tell apache (or whatever you're using) to look in
> the right directory given your STATIC_URL:
>
>  # django-staticfiles: STATIC_URL = '/static_media/'
>  Alias /static_media/ /path/to/your/collected/static/files/

Okay, I did a bit more fiddling last night and you just confirmed that
what I thought had been a workaround was actually the real solution,
namely that I still need to "collect" the default files for a live
server.

Perhaps it's me but that steps feels unintuitive in the docs to me -
the comparison with templates meant I felt I would be just serving up
the files in /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/
directly, after all I don't copy the templates over unless I want to
override them (and yes, I realise that means I really should have
spotted django had a default static directory).

Basically static files is just an easier way to copy the admin
css/js/etc. to the project specific directories rather than serving
them directly from the master location?  collectstatic -l in the
development version is probably the closest to what I assumed would
happen.

I feel a lot clearer now, thank you.

Kevin

-- 
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: can django be used in destop application?

2011-08-24 Thread Thomas Weholt
I remember "way back in the day" when Userland was paving way for what
was to become xml-rpc, feeds etc ( if I remeber correcly ), the core
was a web application running at localhost only. Worked great! I like
the idea and allready have a project for something like this. I've
tried wxpython, pyqt etc and I still make stuff way faster using
django. It doesn't fit every project though.

And another thing; there have been discussion about how to distribute
django projects and a django project distributed as a single binary, a
setup.exe on windows for instance? Sounds nice.

Thomas

On Wed, Aug 24, 2011 at 11:18 AM, Gelonida N  wrote:
>> Curious concept, using Django for a desktop application.
>>
>> Can't think of any reason why you couldn't at least try it :)
>>
>> Cal
>>
>>
> Original poster was rather clear I think,
>
>>     > it seems its orm can be used in destop application, isn't it?
>
>
> It could make sense to use Django orms, because one knows already django
> orms, but one doesn't know SqlAlchemy or any other orms.
>
> This use case is possible, but not that nicely supported.
> you.
>
>
> You can also search for the thread
> "import django models without runing the server",
>
> which would also be applicable for desktop applications using
> django orms
>
>
> On 08/23/2011 07:36 PM, Cal Leeming [Simplicity Media Ltd] wrote:
>
> --
> 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.
>
>



-- 
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: can django be used in destop application?

2011-08-24 Thread Gelonida N
> Curious concept, using Django for a desktop application.
>
> Can't think of any reason why you couldn't at least try it :)
>
> Cal
>
>
Original poster was rather clear I think,

> > it seems its orm can be used in destop application, isn't it?


It could make sense to use Django orms, because one knows already django
orms, but one doesn't know SqlAlchemy or any other orms.

This use case is possible, but not that nicely supported.
you.


You can also search for the thread
"import django models without runing the server",

which would also be applicable for desktop applications using
django orms


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

-- 
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: How to make an app independent on a specific site?

2011-08-24 Thread Gelonida N
On 08/24/2011 08:15 AM, Praveen Krishna R wrote:
> *Even if you write
> 
> from models import Publisher, Book, Author
> 
> its gonna work, inside the books application;
> *
> On Wed, Aug 24, 2011 at 7:09 AM, Jim  > wrote:
> 
It will be working, but I personally don't like relative imports too much.

If you really wanted to do relative imports, then I would use (for newer
python versions  (>= 2.5)



# must be at the beginning of your python file
# the define will avoid any accidental relative imports
from __future__ import absolute_import

afterwards you can 'explicitely perform a relative import with'
from .models import Publisher, Book, Author # note the '.' before models

-- 
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: Error: cannot import name settings

2011-08-24 Thread Reinout van Rees

On 24-08-11 09:54, Mario Gudelj wrote:

Error: cannot import name settings


Are you doing "from django.conf import settings"? Is that going wrong?
Or does django refuse to start? If so, what's your settings environment 
variable like?


And: can you give the full traceback?


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 23-08-11 01:31, Jim wrote:

django.db.utils.DatabaseError: no such table: django_content_type


Which django version, btw? Early 1.2 beta versions had a bug:

https://code.djangoproject.com/ticket/12999


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Admin staticfiles stubbornly hiding behind 404s

2011-08-24 Thread Reinout van Rees

On 23-08-11 13:25, Caomhin wrote:

I confess, I'm lost!  I've just tried starting my first new site since
upgrading to Django 1.3 and the new staticfiles settings seem to be
taunting me.  I've tried a number of variations but every setting I
have returns a 404 for the admin interface css.  Here's what I have
just now:

MEDIA_URL = 'media/'


I'd put a slash in front of that, but that shouldn't be related to your 
admin css problem.



STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'


Looks fine. Suggestion, though:

ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'


STATICFILES_DIRS = (
 '/usr/local/lib/python/site-packages/django/contrib/admin/media',
)


You should not be needing that. staticfiles by default finds all the 
files just fine by looking in the applications' static/ directory.


This directory is an extra location where staticfiles looks, in addition 
to the applications' static/ directories.



%python manage.py findstatic admin/css/dashboard.css
Found 'admin/css/dashboard.css' here:
   /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/
css/dashboard.css


Yep, it finds it through the "django app"'s static/ directory.


%python manage.py findstatic css/dashboard.css
Found 'css/dashboard.css' here:
   /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/
css/dashboard.css


This one is found as you added that STATICFILES_DIRS. The same way as if 
you'd added an extra hardcoded template directory.



%python manage.py findstatic dashboard.css
No matching file found for 'dashboard.css'.


Which is fine, as there is no such file.


So I'm fairly happy that django is finding these files in a sane an
happy manner, and the failure on the final one gives me a sense of
reassurance that the paths are all making sense, but still the
templates are generating  and the stylesheets are not found.


When are they not found? Both in development and on the server? Or only 
on the server?


On the server, you need to tell apache (or whatever you're using) to 
look in the right directory given your STATIC_URL:


  # django-staticfiles: STATIC_URL = '/static_media/'
  Alias /static_media/ /path/to/your/collected/static/files/



Reinout


--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: pydra

2011-08-24 Thread Tom Evans
On Tue, Aug 23, 2011 at 11:44 PM, hinnack  wrote:
> hi all,
>
> Anyone ever used pydra?
> http://code.osuosl.org/projects/pydra/wiki
>
> could not find a thread on the list...
>
> Regards
>
> Henrik
>

Looks like a re-invention of celery/amqp. Think I'll stick with the original.

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: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 23-08-11 01:31, Jim wrote:

 def allow_syncdb(self, db, model):
 # db is a string of database name.
 label = model._meta.app_label
 if label == 'books':
 dbName = 'test'
 else:
 dbName = None
 return dbName == db


I'd do the "if" part as follows:

if label == 'books':
if db == 'test':
return True
return False
if db == 'test':
return False
return None  # None means 'no opinion'.

iirc allow_syncdb() ought to return True/False to indicate whether a 
certain model should be synced to a certain database. So you need to 
make sure *two* things:


- Your special models only end up in your special database and not in 
another.


- Other models (like the django_content_type table that gives you 
problems!) should not end up in your special deatabase.




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: mod_wsgi cannot load MySQLdb

2011-08-24 Thread Reinout van Rees

On 23-08-11 00:37, Jim wrote:

This probably has been discussed many times, but I still can't find any
solution yet. Basically, it turns out that python can load MySQLdb just
fine, but Apache can't load MySQLdb from the wsgi script.



- Does apache use the virtualenv's environment?

- Mod_wsgi: does that use the correct python version? mod_wsgi normally 
uses /usr/bin/python (python 2.5 or 3.2 whatever) and you might have 
used /usr/bin/python2.7.


- Can the apache process find the mysql libraries? Are the environement 
variables different? Try printing "os.environ" from your .wsgi script 
for instance.


Just some brainstorming.


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: cannot import name settings

2011-08-24 Thread Mario Gudelj
Hi guys,

I'm still a noob so please bear with me :)

My friend has made a change to my django project and I got a clone of the
project with his changes from the bitbucket repo, but now when I try to
validate it I get:

Error: cannot import name settings

I tried setting the path to the new project as per
http://www.juiceanalytics.com/writing/django_settings_module/ and I can see
the project folder inside the path but I'm still getting the above error.

django_countries module has been added to the project and it seems to me
that it is causing this issue.

I have it inside installed apps:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'registration',
'django_countries',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

When I comment it out I get a different error which refers to the django
countries being used inside the models.py.

I'm really not sure what do here. I have searched internet for the past hour
and can't find an answer.

My Django version is:

>>> print django.VERSION
(1, 3, 0, 'final', 0)

Thanks everyone.

Mario

-- 
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 Development environment

2011-08-24 Thread Praveen Krishna R
On Windows
Notepad++, django development server, sqlite3, south

On Ubuntu
Vim, MySQL, south, virtualenv


-- 
Thanks and Regards,
*Praveen Krishna 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: How to make an app independent on a specific site?

2011-08-24 Thread Praveen Krishna R
*Even if you write

from models import Publisher, Book, Author

its gonna work, inside the books application;
*
On Wed, Aug 24, 2011 at 7:09 AM, Jim  wrote:

> Greetings, everyone.
>
> I am new to Django, and much of my knowledge comes from the Django book
> version 2 . In the book, a site,
> mysite, is created for demo purposes. And an app, books, is also created for
> demo purposes. In the file, mysite/books/admin.py, there is a line like
> this:
>
>
> from mysite.books.models import Publisher, Author, Book
>
> It seems to me that this line makes the app dependent on the name of the
> site, which is mysite. There is a possibility that an app you have developed
> for a site might turn out to have generic use. So, I think it is a good idea
> to always keep an app independent on the site as much as possible.
>
> Here is the question. Is it possible that to store the site name into a
> variable, such as site_name, then construct a statement like the following?
>
> statement = 'from ' + site_name + '.books.models import Publisher' 
> exec(statement)
> # I am not sure if exec is a legitimate function. Here is just an example
>
>
>
>
>
>
>
>
>  --
> 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/-/Jn_07ca2t6MJ.
> 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.
>



-- 
Thanks and Regards,
*Praveen Krishna 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.