Re: [Fwd: Custom field in JSON serializer]

2008-06-28 Thread Will Larson

Ganesh,

You'll need to create your own serializer. You can do this by  
subclassing django.core.serializers.base (or perhaps you might  
subclass the json one, there are a number of ways to skin the cat  
here), and then registering it with  
django.core.serializers.register_serializer, which is used like this:

 from django.core.serializers import register_serializer, serialize
 register_serializer("extra_json",  
"myapp.serializer.myjsonserializer")
 objs = MyModel.objects.all()
 data = serialize('extra_json', objs)

Look around the django.core.serializers files at the existing  
serializers for the details of how to implement your subclass.

Best of luck,
Will


On Jun 28, 2008, at 7:03 PM, M.Ganesh wrote:

>
>  people who asked after me got their answers, sometimes
> within 15 minutes. I've not got any answers 
>
> Should I reword my query?
>
> Regards Ganesh
>
>
>  Original Message 
>
> Hi All,
>
> I picked up this sample code from django documentation:
>
> from django.core import serializers
> data = serializers.serialize('xml', SomeModel.objects.all(),
> fields=('name','size'))
>
> How do I extend this to do the following:
>
> data = serializers.serialize('xml', SomeModel.objects.all(),
> fields=('name','size', '__unicode__'))
>
> Thanks in advance
>
> Regards Ganesh
>
>
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unable to upload PNG's

2008-06-23 Thread Will Larson
Julian,

This is a PIL issue that appears to be biting a lot of people.  
Googling for "PIL PNG problem" will  help, but this link might be a  
good starting point.

Best,
Will

On Jun 23, 2008, at 6:02 PM, jurian wrote:

>
> I am currently getting an error when I attempt to upload a PNG image
> from the admin side.
>
> Error: Upload a valid image. The file you uploaded was either not an
> image or a corrupted image.
>
> There is nothing wrong with the image, and I've made sure that my PIL
> is setup correctly.
>
> 
> PIL 1.1.6 BUILD SUMMARY
> 
> version   1.1.6
> platform  linux2 2.5.2 (r252:60911, Mar 27 2008, 15:17:32)
>   [GCC 4.1.3 20070929 (prerelease) (Ubuntu
> 4.1.2-16ubuntu2)]
> 
> *** TKINTER support not available
> --- JPEG support ok
> --- ZLIB (PNG/ZIP) support ok
> --- FREETYPE2 support ok
> 
>
> Any clues will be appreciated, 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django on apache and mod_python.... and problems

2008-06-21 Thread Will Larson
Hi,

> The summary of error messages is this:
>
>> AttributeError: 'module' object has no attribute 'blog'
>
> I've made sure that /papastudio/blog has __init.py__, and that it's
> listed in INSTALLED_APPS (which is logical since the site actually
> works if I ./manage.py runserver).

Did you follow the mod_python deploy instructions? There are a few  
things that may be happening.

1. The file needs to be '__init__.py', not '__init.py__', but I think  
that is probably just a typo in this email.
2. Make sure you have __init__.py in both `/papastudio/` and `/ 
papastudio/blog/`.
3. Is the base import (depending on what the entry in your  
INSTALLED_APPS looks like, if its `papastudio.blog` then it would be  
`papastudio`) in the Python path for your mod_python deploy? You will  
probably need to explicitly add it like in the instructions linked  
above. Your deploy will look something like this:

 
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 SetEnv DJANGO_SETTINGS_MODULE papastudio.settings
 PythonDebug Off
 PythonPath "['/path/to/papastudio'] + sys.path"
 

>
> I've left the site in debug mode, so that I can see what's going on,
> but the errors are the same if I set debug to False.
>

Thats because they are being caught by mod_python, and not by Django.  
To turn it off change `PythonDebug On` to `PythonDebug Off` in your  
mod_python config file.

Best of luck,
Will



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: complaint about production db when running unit tests

2008-06-18 Thread Will Larson

Andrew,

Running 'manage.py test' will create new tables, but not a new  
database. It can't create a new database, since it doesn't know what  
settings to use for that new database. However, your data stored in  
your database won't get overwritten since you will be using a  
temporary table.

Best,
Will

On Jun 19, 2008, at 7:16 AM, Andrew D. Ball wrote:

>
> Good afternoon.
>
> I thought that unit tests run by 'manage.py test' create
> a test db that is separate from the production database
> by default, prepending 'test_' to the database
> name specified by settings.DATABASE_NAME or using
> settings.TEST_DATABASE_NAME for the name of the
> new database.
>
> I'm using Django 0.96.1, and 'python manage.py test'
> will complain unless the production database
> is created and I've run 'manage.py syncdb'.
>
> Any idea why?
>
> Peace,
> Andrew
> -- 
> ===
> Andrew D. Ball
> [EMAIL PROTECTED]
> Software Engineer
> American Research Institute, Inc.
> http://www.americanri.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Request in a template

2007-11-21 Thread Will Larson


> I have an parameter in my querystring which i would like to access in
> a template, fx:
>
> ---
> 
> ---
>


http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context- 
processors/

Shows you how to do just that.

But, I would recommend handling that a bit different. Specifically in  
your view mapping the url you want to return to to a variable in the  
template ("return_url", etc), so that in your template you'd have

 

In my mind this is meaningful because it preserves the distinction  
between the template deciding how to present information, and the  
views deciding what information to present. Also you would likely  
want to do some preprocessing on the url to make sure its a valid  
value (also, to prevent abject failure in a situation where there was  
no get request, or the get request did not have the url field. If  
only input was sanitary...), which you couldn't do in the template,  
but is quite doable in the views file.

This may seem like a needless distinction, and it is... as long as  
what you are doing isn't important or particularly large.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---