Configuring Paths for FileField ?

2008-12-01 Thread Eric

Hi!

I'm new at Django, but I've been having relatively good luck.  I've
recently hit a big of a wall using FileField.  I have set up the paths
correctly enough that I can upload files to  /my_site/uploads/photos,
but when I view the model containing the FileField in the admin
interface, it shows the URL of the photo as:
http://localhost:8000/uploads/photos/flier.jpg

Clicking on this link, of course, produces a 404 error.

Is there an accepted way to set up the routes to make this /uploads/
directory publicly accessible?

Thanks for your time.
--~--~-~--~~~---~--~~
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: GeoDjango in Ubuntu 8.10, Segmentation Fault

2008-12-01 Thread Info Cascade

FWIW --

I got this working in CentOS5.2 by removing the default (yum installed)
version of apache, and compiling the latest version, 2.2.10.
While I was at it, I compiled the latest version of mod_python.
That was all it took, and now, no more segmentation violations.

Thanks,
Liam

Justin Bronn wrote:
>> Based on comments in a separate thread, GeoDango may have issues with
>> multithreaded configuration. Which Apache MPM was being used for each
>> Apache version, prefork or worker? The worker MPM uses threads and so
>> that could be the culprit.
>> 
>
> Yes -- the libraries GeoDjango uses, GEOS and GDAL, are not thread
> safe.  Thus, it is highly recommended to use the prefork version of
> Apache.
>
>   
>> In a Python Shell, I am able to perform queries on my spatial models
>> successfully.  In a web browser, I get a plain white screen if any
>> code is executed that works with spatially enabled models.
>> 
>
> I created an Ubuntu 8.10 VM to try and test out this problem.
> However, the only way that I could reproduce your exact problem
> (segfault upon HTTP request) is when using the mpm-worker (threaded)
> Apache.  When using the prefork, however, I was able to get both
> mod_python and mod_wsgi to work with a simple demonstration app [1].
> I think mpm-worker is the default when you do `apt-get install
> apache2`, so make sure you have it removed, e.g., `apt-get remove
> apache2-mpm-worker; apt-get install apache2-mpm-prefork`.
>
> BUT, I found another issue -- while I could login to and browse the
> admin interface, whenever I tried to view a geographic model an
> exception would get raised (but no segfault) deep in the admin widgets
> [2], crashing the app.  While this crash occurs in 8.10 it does _not_
> happen in my 8.04 VM.  Thus, this leads me to believe that it may be a
> manifestation of the same troubles you're experiencing.  Moreover,
> this admin crash happens with _both_ mod_python and mod_wsgi in 8.10
> (mod_wsgi configured with `threads=1`).
>
> Needless to say, this behavior has me perplexed at the moment, and due
> to my finals I'm not going to have a lot of time to dig in deeper
> until next month.  Perhaps there's a clash of the libraries that are
> linked to Apache and the ones used by the packaged versions of GEOS/
> GDAL, or maybe it's caused by Ubuntu's AppArmor (confined to just CUPS
> in 8.04) -- but these are just potential possibilities.
>
>   
>> Justin was good enough to run a test case I created and was unable to
>> duplicate the error.  I'm wondering now about the exact versions of
>> Apache and other components that might be causing the problem.
>> 
>
> I still have the CentOS 5.2 VM, and I'll test it out again, but I'm
> not sure yet that this could be the same issue as you reported in
> October.  It's a different distribution that used significantly older
> versions (that also worked in my tests).
>
> [1] http://geodjango.org/hg/world
> [2] 
> http://code.djangoproject.com/browser/django/trunk/django/contrib/gis/admin/widgets.py#L43
> >
>
>   


--~--~-~--~~~---~--~~
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: admin.py -- AlreadyRegistered

2008-12-01 Thread Roland van Laar

djan wrote:
> Hello.
>
> I'm following along with djangobook.com and trying to make necessary
> changes to port django to version 1.0. In Django's Site
> Administration, chapter 6, I run into the error:
>
>
> Exception Type:   AlreadyRegistered
> Exception Value:  The model Book is already registered
> Exception Location:   /usr/local/lib64/python2.5/site-packages/django/
> contrib/admin/sites.py in register, line 64
>
>   
Probably:
Try to restart the django development server.
The django dev server doesn't reload the admin.py file properly when it's
edited or when it encounters an error in that file.


> I used the site administration site successfully with just "Book", and
> then when I attempted to add the other models (Auther, Publisher), I
> received the above error.
>
> in admin.py I have:
>
> from django.contrib import admin
> from models import Book, Author, Publisher
>
>   
On another note, you don't have to do this:

> class BookAdmin(admin.ModelAdmin):
> pass
> admin.site.register(Book, BookAdmin)
>   
admin.site.register(Book)

would suffice.

> class AuthorAdmin(admin.ModelAuthor):
> pass
> admin.site.register(Author, AuthorAdmin)
>
> class PublisherAdmin(admin.ModelPublisher):
> pass
> admin.site.register(Publisher, PublisherAdmin)
>
> When I updated admin.py I ran:
> python manage.py syncdb
>
> It is as if the database wasn't "synced" though, and that two
> instances of this model are trying to be created.
>
> When I searched around for this error, I found instances of this
> occuring in 0.96, with the model being called several times. The Admin
> changes in 1.0 were said to resolve this, so perhaps it is something
> else.
>
> I appreciate any help. Thanks!
>
>   
Regards,

Roland



--~--~-~--~~~---~--~~
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: XML templates

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote:
> I tried the code below:
> 
> from django.template import loader, Context
> 
> def NewspaperSelect(request,u_id):
> t=loader.get_template(r'C:\django\noddler\news\template.vxml')
>   c=Context({ 'topic':'news', 'content':pn })
>return HttpResponse(t.render(c), mimetype='application/xml')
> 
> I verified that the file is in the location. But when i compile it
> keeps telling that template file does not exist. What to do?

get_template() doesn't take a full path to a file. It takes the name of
a template, possibly with some directories in front -- but it's a
relative path. What the path is relative to depends on the template
loader being used. Unless you've done anything special to your setup,
Django will try the application loader first -- appending the path to
/templates/ for each app_name that you have installed. Then it
will try the filesystem loader, which will append the path to each
diretcory in the TEMPLATE_DIRS setting and see if it exists.

So you either need to set up TEMPLATE_DIRS or put the templates in a
templates/ directory inside one (or more) of your applications.

This ends up making the code very portable, by the way, since when you
install it somewhere else, you only have to change the TEMPLATE_DIRS
settings (at most) and all your templates will still load correctly.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: XML templates

2008-12-01 Thread Vicky

I tried the code below:

from django.template import loader, Context

def NewspaperSelect(request,u_id):
t=loader.get_template(r'C:\django\noddler\news\template.vxml')
c=Context({ 'topic':'news', 'content':pn })
   return HttpResponse(t.render(c), mimetype='application/xml')

I verified that the file is in the location. But when i compile it
keeps telling that template file does not exist. What to do?



On Dec 1, 4:57 pm, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> On Dec 1, 2008, at 7:51 PM, Vicky wrote:
>
>
>
> > Can we use XML files as templates instead of HTML?
>
> Anything that comes as a plain text file can be produced by a  
> template: HTML, XML, plain text, email, iCAL, source code...
>
> Yours,
> Eric
>
>
--~--~-~--~~~---~--~~
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: Form POST Issue

2008-12-01 Thread please smile
Thanks Karen Tracey,I typecast the posted  value as integer. now Its works
fine.


On Tue, Dec 2, 2008 at 3:28 AM, Karen Tracey <[EMAIL PROTECTED]> wrote:

> In the future, if you click "Switch to copy-and-paste-view" and then just
> copy and paste the contents of the traceback window, that is generally
> easier to deal with.  The traceback in your screenshot (which shows your
> photosapp/views.py on line 104 calling paginator.page) doesn't match up with
> the code you originally showed (where I don't see any call to
> paginator.page) so it's a little hard to be entirely sure what is going
> wrong.  I'd guess you are passing in a unicode value from the POST data and
> the paginator is expecting an integer.  So if you cast your value to an int
> before handing it to the Paginator that may fix it.  Possibly the Paginator
> should handle this more gracefully, but I'm not sure since I don't have a
> full idea of what you code is doing, exactly, and I'm traveling so don't
> have time to try to replicate the error myself at the moment.
>
> Karen
>
> >
>

--~--~-~--~~~---~--~~
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: time help (again)

2008-12-01 Thread humanstalker

Hi

Just thought i would help out anyway even though this is solved.

d = datetime.datetime.now() - datetime.datetime.strptime
(dbValueHere,"%Y-%m-%d") # Does a date diff between today and the date
from the DB, change "%Y-%m-%d" to suit the format of you string.Also
make sure you set the dbValueHere or replace it with you own value.

print d.seconds # Prints the seconds
print d.days #Prints the days

This allows you to get the days and seconds , its not much different
than the other solutions presented.

~stalkerh

--~--~-~--~~~---~--~~
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: time help (again)

2008-12-01 Thread Kenneth Gonsalves

On Tuesday 02 Dec 2008 10:31:11 am Bobby Roberts wrote:
> > http://www.python.org/doc/2.5.2/lib/datetime-timedelta.html
>
> yeah i said I don't understand this.

>>> x =datetime(2008,12,10,20)
>>> y=datetime(2008,12,10,23)
>>> z = y-x
>>> z
datetime.timedelta(0, 10800)
>>> print z
3:00:00


-- 
regards
KG
http://lawgon.livejournal.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: time help (again)

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 20:52 -0800, Bobby Roberts wrote:
> ok day 7 and no luck.  I really need help.  I need to calculate the
> difference between two dates, one pulled from the database, and one as
> the NOW time.  I'm hoping someone out there can help me and explain
> the code to me.  Yes I've read the docs but they don't make sense to
> me thus the reason i'm asking for help.  Thank you in advance.

There's not a lot of (any?) Django content here, so you might be better
suited asking in comp.lang.python or somewhere similar. Still, here's a
brief guide:


> 
> the first date is pulled from the database and is in the format:
> 2008-12-01 22:02:59

So you need to convert this to datetime object. The portable way would
be:

import datetime
import time

time_tuple = time.strptime(value, '%Y-%m-%d %H:%M:%S')
timestamp = time.mktime(time_tuple)
dt = datetime.fromtimestamp(timestamp)

where "value" is the string you've retrieved from the database. If
you're using Python 2.5, datetime.strptime() exists, so you can do the
same thing in more or less one step -- without having to go through the
intermediate tuple and timestamp formats.

> the second date is the now time in the format:  2008-12-01
> 22:32:47.391200

Not really. The second date is a datetime object -- the thing returned
by datetime.now(). When you print it, it's converted to a string, which
is the above representation. 

At this point you have two datetime object, so subtracting them will
give you a timedelta object. Then you can access the days and seconds
attributes to get the result in any format you like.

Poke around with a few examples at the interactive prompt to see how
this works.

[...]
> Can anyone tell me how to do this in python.  I'm coming from an asp
> background where there is a built in function to determine this.

The general principle operating here (in Python), is that arithmetic can
be performed on date/datetime/time objects. You get back an object,
since there's more than one thing you might want to do with the result,
so the object provides access to the data, as well as the common
arithmetical operations.

You could also look at just doing the subtraction at the database level.
Every database has a way to retrieve the value "now" (usually it will be
something like CURRENT_TIMESTAMP and variations thereof).

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: time help (again)

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 21:01 -0800, Bobby Roberts wrote:
> > http://www.python.org/doc/2.5.2/lib/datetime-timedelta.html
> 
> yeah i said I don't understand this.

Well, you said you didn't understand "the docs", but you didn't mention
which documentation you had found. So Kenneth's answer isn't entirely
unreasonable.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: time help (again)

2008-12-01 Thread Bobby Roberts

> http://www.python.org/doc/2.5.2/lib/datetime-timedelta.html

yeah i said I don't understand this.
--~--~-~--~~~---~--~~
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: time help (again)

2008-12-01 Thread Kenneth Gonsalves

On Tuesday 02 Dec 2008 10:22:21 am Bobby Roberts wrote:
> Can anyone tell me how to do this in python.  I'm coming from an asp
> background where there is a built in function to determine this.

http://www.python.org/doc/2.5.2/lib/datetime-timedelta.html

-- 
regards
KG
http://lawgon.livejournal.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: Getting form data using Form object

2008-12-01 Thread Felipe Sodré Silva
Thanks a lot Malcolm!

On Tue, Dec 2, 2008 at 2:46 AM, Malcolm Tredinnick <[EMAIL PROTECTED]
> wrote:

>
>
> On Tue, 2008-12-02 at 02:30 -0200, Felipe Sodré Silva wrote:
> > Hi everyone.
> >
> > When I get the data from a form, I'm processing it using request.POST
> > object, like this:
> >
> > def process(request):
> > ..var = request.POST['some_field_id']
> >
> > I want to know if it's possible to get these values using a Form
> > object, like this:
>
> Not only possible, highly recommended. Have a look at
>
> http://docs.djangoproject.com/en/dev/topics/forms/#processing-the-data-from-a-form
>
> Using the form class to first validate the data will save you a lot of
> effort.
>
> Regards,
> Malcolm
>
>
>
> >
>

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



time help (again)

2008-12-01 Thread Bobby Roberts

ok day 7 and no luck.  I really need help.  I need to calculate the
difference between two dates, one pulled from the database, and one as
the NOW time.  I'm hoping someone out there can help me and explain
the code to me.  Yes I've read the docs but they don't make sense to
me thus the reason i'm asking for help.  Thank you in advance.

the first date is pulled from the database and is in the format:
2008-12-01 22:02:59

the second date is the now time in the format:  2008-12-01
22:32:47.391200

I need to calculate the difference between the two dates in total
amount of seconds.

Here's what i've got so far:

  ctx.locals.session_id=ctx.sesid()
  c = ctx.request.db.cursor()
  c.execute('''SELECT hit_date from tablename where session_id=%s
order by id desc limit 0,1''', (ctx.locals.session_id))
  ctx.locals.lasttimestamp = c.fetchone()
  hittime=ctx.locals.lasttimestamp
  nowtime=datetime.datetime.now()
  totalseconds=nowtime-hittime


Can anyone tell me how to do this in python.  I'm coming from an asp
background where there is a built in function to determine this.




--~--~-~--~~~---~--~~
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: Getting form data using Form object

2008-12-01 Thread Malcolm Tredinnick


On Tue, 2008-12-02 at 02:30 -0200, Felipe Sodré Silva wrote:
> Hi everyone.
> 
> When I get the data from a form, I'm processing it using request.POST
> object, like this:
> 
> def process(request):
> ..var = request.POST['some_field_id']
> 
> I want to know if it's possible to get these values using a Form
> object, like this:

Not only possible, highly recommended. Have a look at
http://docs.djangoproject.com/en/dev/topics/forms/#processing-the-data-from-a-form

Using the form class to first validate the data will save you a lot of
effort.

Regards,
Malcolm



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



Getting form data using Form object

2008-12-01 Thread Felipe Sodré Silva
Hi everyone.

When I get the data from a form, I'm processing it using request.POST
object, like this:

def process(request):
..var = request.POST['some_field_id']

I want to know if it's possible to get these values using a Form object,
like this:

def process(request):
..form = MyFormClass(request.POST)
..var = form.some_field

assume that MyFormClass is the actual Form class that generates the form to
the user.

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: Model similar to a spreadsheet

2008-12-01 Thread Dan
I don't understand what you are trying to do. Would you mind describing the
real life problem under it rather than how you try to solve it? It would
help understand what you need.

On Mon, Dec 1, 2008 at 2:10 PM, Stefan <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I'm new to Django and have some problems on how to create the models.
>
> What I want to do is something similar to a spreadsheet, but with more
> than one data field per intersection.
>
> Basically like this: (http://dpaste.com/hold/95128/)
>
> Items/Members: Person_A | Person_B | Person_C
> Item_1: x=1,y=3 | x=4,y=2 | x=7,y=5
> Item_2: x=8,y=2 | x=2,y=0 | x=8,y=4
> Item_3: x=4,y=9 | x=5,y=9 | x=3,y=1
> .
> .
> (and so on)
>
> This is the most I could figure out so far (I know, it's almost
> nothing): http://dpaste.com/hold/95127/
>
> The main problems are the x= and y= for the items, because each item
> has a lot of x and y, namely one x and one y for each person.
>
> I also don't understand if I need to use the ForeignKey in Item and
> Person referring to the CostSheet or the ManyToManyField in the
> CostSheet referring to Item and Person or even both.
>
> Thanks for your help.
>

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



admin.py -- AlreadyRegistered

2008-12-01 Thread djan

Hello.

I'm following along with djangobook.com and trying to make necessary
changes to port django to version 1.0. In Django's Site
Administration, chapter 6, I run into the error:


Exception Type: AlreadyRegistered
Exception Value:The model Book is already registered
Exception Location: /usr/local/lib64/python2.5/site-packages/django/
contrib/admin/sites.py in register, line 64

I used the site administration site successfully with just "Book", and
then when I attempted to add the other models (Auther, Publisher), I
received the above error.

in admin.py I have:

from django.contrib import admin
from models import Book, Author, Publisher

class BookAdmin(admin.ModelAdmin):
pass
admin.site.register(Book, BookAdmin)

class AuthorAdmin(admin.ModelAuthor):
pass
admin.site.register(Author, AuthorAdmin)

class PublisherAdmin(admin.ModelPublisher):
pass
admin.site.register(Publisher, PublisherAdmin)

When I updated admin.py I ran:
python manage.py syncdb

It is as if the database wasn't "synced" though, and that two
instances of this model are trying to be created.

When I searched around for this error, I found instances of this
occuring in 0.96, with the model being called several times. The Admin
changes in 1.0 were said to resolve this, so perhaps it is something
else.

I appreciate any help. 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: Model that only needs 1 data row

2008-12-01 Thread CLIFFORD ILKAY
JGAllen23 wrote:
> I am building a website for a client and one of the pages they need is
> an "about us" page which would just require 1 row of data.  What is
> the best way to handle this case where a model would only need 1 data
> row?

Override the save() method for that model. E.g.

class FeaturedProduct(models.Model):
product = models.ForeignKey(Product)
description = models.TextField(blank=True, null=True)

class Admin:
pass

class Meta:
verbose_name_plural = 'Featured Product on Home Page'

def save(self):
'''
There can only be one featured product and it goes on the home
page. Forcing the id to 1 ensures that any attempt to create a
new featured product will only modify the existing one.
'''
self.id = 1
super(FeaturedProduct, self).save()

def __str__(self):
return self.product.name+' - '+self.product.product_numberx
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Model that only needs 1 data row

2008-12-01 Thread alex.gay...@gmail.com

Take a look at django.contrib.flatpages.

On Dec 1, 9:36 pm, JGAllen23 <[EMAIL PROTECTED]> wrote:
> I am building a website for a client and one of the pages they need is
> an "about us" page which would just require 1 row of data.  What is
> the best way to handle this case where a model would only need 1 data
> row?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model that only needs 1 data row

2008-12-01 Thread JGAllen23

I am building a website for a client and one of the pages they need is
an "about us" page which would just require 1 row of data.  What is
the best way to handle this case where a model would only need 1 data
row?
--~--~-~--~~~---~--~~
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: urlpatterns question

2008-12-01 Thread Malcolm Tredinnick


On Tue, 2008-12-02 at 10:07 +0800, Earl Lapus wrote:
> On Tue, Dec 2, 2008 at 9:50 AM, Malcolm Tredinnick
> <[EMAIL PROTECTED]> wrote:
> >
> >
> > Yes, because admin.site.root isn't a function. It's a method on a class
> > (which implies a difference in the way things are called).
> >
> > There's a bit of history going on here: in the early days, all the view
> > functions had to be strings. We realised it was a bit limiting, because,
> > amongst other things, it can get quite verbose and it prevented usings
> > things like class methods or objects with a __call__ function. Thus, the
> > ability to use proper Python objects there was added a few years ago.
> >
> > Regards,
> > Malcolm
> >
> 
> Okay. To sum this all up, it's safe to say that single quotes should
> be applied only if you're calling a function in a module

Well, you can stop at that point (you don't need the second part, since
class methods aren't module-level functions). Realise also that using
the string form -- and it's just a normal Python string, so whether you
use single quotes or double quotes or even triple quotes is up to you --
is entirely optional. Personally, I prefer to avoid using the string
version altogether, so that I know I've imported the right functions
(not typos in the string) and because it usually ends up being shorter.
But it's entirely personal preference.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: urlpatterns question

2008-12-01 Thread Earl Lapus

On Tue, Dec 2, 2008 at 9:50 AM, Malcolm Tredinnick
<[EMAIL PROTECTED]> wrote:
>
>
> Yes, because admin.site.root isn't a function. It's a method on a class
> (which implies a difference in the way things are called).
>
> There's a bit of history going on here: in the early days, all the view
> functions had to be strings. We realised it was a bit limiting, because,
> amongst other things, it can get quite verbose and it prevented usings
> things like class methods or objects with a __call__ function. Thus, the
> ability to use proper Python objects there was added a few years ago.
>
> Regards,
> Malcolm
>

Okay. To sum this all up, it's safe to say that single quotes should
be applied only if you're calling a function in a module -AND- if you
want to call a class method, then you shouldn't use single quotes (I
hope I got that right).

Thanks for the inputs, I really appreciate it. =)



-- 
There are seven words in this sentence.

--~--~-~--~~~---~--~~
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: mod_python setup on Apache virtual host

2008-12-01 Thread Abe

I just witnessed the same behavior but haven't found the solution.

I'm using Ubuntu 8.04, Django 1.0, and Apache 2.2 with mod_python.

Abe

On Nov 15, 10:16 pm, Chuck22 <[EMAIL PROTECTED]> wrote:
> I did not use ErrorDocument directives in my httpd.config.
>
> Here is my Apache error log:
>
> [Sun Nov 16 03:00:12 2008] [error] [client ] mod_python (pid=3296,
> interpreter='domain.com', phase='PythonHandler',
> handler='django.core.handlers.modpython'): Application error
> [Sun Nov 16 03:00:12 2008] [error] [client ] ServerName: 'domain.com'
> [Sun Nov 16 03:00:12 2008] [error] [client] DocumentRoot: 'C:/Apache/
> homedomain'
> [Sun Nov 16 03:00:12 2008] [error] [client ] URI: '/'
> [Sun Nov 16 03:00:12 2008] [error] [client ] Location: None
> [Sun Nov 16 03:00:12 2008] [error] [client ] Directory: None
> [Sun Nov 16 03:00:12 2008] [error] [client] Filename: 'C:/Apache/
> homedomain/'
> [Sun Nov 16 03:00:12 2008] [error] [client] PathInfo: ''
> [Sun Nov 16 03:00:12 2008] [error] [client ] Traceback (most recent
> call last):
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\Lib\
> \site-packages\\mod_python\\importer.py", line 1537, in HandlerDispatch
> \n    default=default_handler, arg=req, silent=hlist.silent)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\Lib\
> \site-packages\\mod_python\\importer.py", line 1229, in _process_target
> \n    result = _execute_target(config, req, object, arg)
> [Sun Nov 16 03:00:12 2008] [error] [client ]   File "C:\\Python25\\Lib\
> \site-packages\\mod_python\\importer.py", line 1128, in _execute_target
> \n    result = object(arg)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\core\\handlers\\modpython.py", line 222, in
> handler\n    return ModPythonHandler()(req)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\core\\handlers\\modpython.py", line 195, in
> __call__\n    response = self.get_response(request)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\core\\handlers\\base.py", line 128, in
> get_response\n    return self.handle_uncaught_exception(request,
> resolver, exc_info)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\core\\handlers\\base.py", line 160, in
> handle_uncaught_exception\n    return callback(request, **param_dict)
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\views\\defaults.py", line 88, in server_error
> \n    t = loader.get_template(template_name) # You need to create a
> 500.html template.
> [Sun Nov 16 03:00:12 2008] [error] [client]   File "C:\\Python25\\lib\
> \site-packages\\django\\template\\loader.py", line 80, in get_template
> \n    source, origin = find_template_source(template_name)
> [Sun Nov 16 03:00:12 2008] [error] [client ]   File "C:\\Python25\\lib\
> \site-packages\\django\\template\\loader.py", line 73, in
> find_template_source\n    raise TemplateDoesNotExist, name
> [Sun Nov 16 03:00:12 2008] [error] [client ] TemplateDoesNotExist:
> 500.html
>
> It seems an internal applicaiton error - 500 error. But I don't know
> where is the problem. Can you see what's wrong with my Virtual Host
> setup? Or tell me what is the correct way to set up Apache Virtual
> Host for Django.
>
> On Nov 16, 6:12 am, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:> Are you setting ErrorDocument directives in Apache configuration?
>
> > If you are then disable them and then actual error may not be masked.
>
> > Have you looked in Apache error log for more information?
>
> > Graham
>
> > On Nov 16, 5:53 am, Chuck22 <[EMAIL PROTECTED]> wrote:
>
> > > Here is what I tried.
>
> > > 
> > >     DocumentRoot "C:/Apache/homedomain"
> > >     ServerName domain.com
> > >     ServerAliaswww.domain.com
>
> > >     SetEnv DJANGO_SETTINGS_MODULE homedomain.settings
> > >     SetHandler mod_python
> > >     PythonHandler django.core.handlers.modpython
> > >     PythonPath "['C:/Apache'] + sys.path"
> > >     PythonDebug On
>
> > > 
>
> > > But I got error:
>
> > > ***
> > > MOD_PYTHON ERROR
>
> > > ProcessId:      1708
> > > Interpreter:    'domain.com'
>
> > > ServerName:     'domain.com'
> > > DocumentRoot:   'C:/Apache/homedomain'
>
> > > URI:            '/'
> > > Location:       None
> > > Directory:      None
> > > Filename:       'C:/Apache/homedomain/'
> > > PathInfo:       ''
>
> > > Phase:          'PythonHandler'
> > > Handler:        'django.core.handlers.modpython'
>
> > > Traceback (most recent call last):
>
> > >   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line
> > > 1537, in HandlerDispatch
> > >     default=default_handler, arg=req, silent=hlist.silent)
>
> > >   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line
> > > 1229, in _process_target
> > >     result = 

Re: urlpatterns question

2008-12-01 Thread Malcolm Tredinnick


On Tue, 2008-12-02 at 09:31 +0800, Earl Lapus wrote:
> On Mon, Dec 1, 2008 at 10:06 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:
> >>
> >> So, what is the difference between a callback function that is
> >> enclosed on single quotes from that which is not?
> >
> > Nothing really:
> >
> > http://docs.djangoproject.com/en/dev/topics/http/urls/#passing-callable-objects-instead-of-strings
> >
> > Karen
> >
> 
> hi, just a small follow-up.
> 
> if there's no difference then why do I get an error when i put single
> quotes around the admin callback as in,
> (r'^admin/(.*)', 'admin.site.root')
> 
> perhaps admin.site.root is an exception to the rule?

Yes, because admin.site.root isn't a function. It's a method on a class
(which implies a difference in the way things are called).

There's a bit of history going on here: in the early days, all the view
functions had to be strings. We realised it was a bit limiting, because,
amongst other things, it can get quite verbose and it prevented usings
things like class methods or objects with a __call__ function. Thus, the
ability to use proper Python objects there was added a few years ago.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Is the initial value of a form field available in the template?

2008-12-01 Thread ChrisK



On Dec 1, 5:44 pm, ChrisK <[EMAIL PROTECTED]> wrote:
> > I often have this need so I created a custom widget where I just set
> > the readonly attribute on a TextInput widget:
>
> > class LabelWidget(forms.TextInput):
>
> Thanks but ... it seems that form.as_p doesn't understand how to
> display this

Ooops. Never mind.
--~--~-~--~~~---~--~~
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: Is the initial value of a form field available in the template?

2008-12-01 Thread ChrisK



> I often have this need so I created a custom widget where I just set
> the readonly attribute on a TextInput widget:
>
> class LabelWidget(forms.TextInput):

Thanks but ... it seems that form.as_p doesn't understand how to
display this!
--~--~-~--~~~---~--~~
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-admin makemessages - excluding folders

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 16:00 -0800, Aljosa Mohorovic wrote:
> i usually use svn:externals to add django, extensions, evolution and
> other stuff to my projects but when i use makemessages in this
> situation it generates locale for everything in current folder.
> i've added some code to makemessages to enable excluding folders by
> pattern to resolve my current situation:
> $ django-admin makemessages  -l hr --exclude_regex="^\.\/(django|
> photologue)"
> 
> i'm sure that there is a better way (since this introduces problems
> when i update django), any tips?

Well, there might be conflicting requirements here, it depends on what
you're really after.

Ticket #7050 is about excluding directories that have their own locale/
directory, which is quite a reasonable idea. Then, if a directory
already has i18n support, it isn't included in the project-level files.
So that probably solves your main problem.

It's not clear that just allowing arbitrary files to be excluded is
something that's a really good idea, since collecting all the strings
for translation is kind of the idea (I'm talking about the case where
there isn't an application-level locale/ directory here). If strings
from some file aren't meant to be included in the PO files, they
wouldn't be marked for translation.

As a practical matter, if you want to maintain something like your
modification without modifying Django, the solution might be to create
your own custom management command. That command will handle the extra
option and then call the default make_messages() function. You could put
that command into an app that contains any other utility code you carry
around from project to project (for example, common template tags, etc).

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: How to return Admin to previous filters after save?

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 14:54 -0800, cyberjack wrote:
> I have an admin interface managing a few thousand records. Finding a
> record requires heavy use of multiple list_filter selections. However,
> once a user edits a record, the admin interface redirects to the root
> admin URL and loses the filter state.
> 
> Is there an easy way to have the admin editor return to the calling
> URL after a form submit?

Yes there is: wait until Django 1.1 is released. It's item "Admin-08" in
http://code.djangoproject.com/wiki/Version1.1Features .


Regards,
Malcolm



--~--~-~--~~~---~--~~
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: urlpatterns question

2008-12-01 Thread Earl Lapus

On Mon, Dec 1, 2008 at 10:06 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:
>>
>> So, what is the difference between a callback function that is
>> enclosed on single quotes from that which is not?
>
> Nothing really:
>
> http://docs.djangoproject.com/en/dev/topics/http/urls/#passing-callable-objects-instead-of-strings
>
> Karen
>

hi, just a small follow-up.

if there's no difference then why do I get an error when i put single
quotes around the admin callback as in,
(r'^admin/(.*)', 'admin.site.root')

perhaps admin.site.root is an exception to the rule?

-- 
There are seven words in this sentence.

--~--~-~--~~~---~--~~
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: testing template tags

2008-12-01 Thread Malcolm Tredinnick


On Mon, 2008-12-01 at 07:14 -0800, Richard Szopa wrote:
> Hello,
> 
> I have written some doctests for my custom template tags, but
> `manage.py test my_app' doesn't seem to notice it. There is an
> __init__.py file in the templatetags directory, but apparently that is
> not sufficient.

Are you assuming that "manage.py test my_app" runs all doctests in every
file? Because that isn't the case. Quoting
http://docs.djangoproject.com/en/dev/topics/testing/ :

For a given Django application, the test runner looks
for doctests in two places:
  * The models.py file. You can define module-level
doctests and/or a doctest for individual models.
It's common practice to put application-level
doctests in the module docstring and model-level
doctests in the model docstrings.
  * A file called tests.py in the application
directory -- i.e., the directory that holds
models.py. This file is a hook for any and all
doctests you want to write that aren't
necessarily related to models.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Does Django have a function that can be called by every view function ?

2008-12-01 Thread David Shieh

Thank you , guys ~
Your help are really good for me ~

On Dec 1, 11:23 pm, Jon Loyens <[EMAIL PROTECTED]> wrote:
> Another +1 for decorators.  In fact, the example David S uses
> authentication and logins as an example of what he wants to do and its
> already handled as a decorator thus giving him a decent pattern to
> follow.  David S, I'd suggest you look up the @login_required
> decorator and even look through the Django code to see how it's
> implemented.  Don't be afraid of cruising through the code.  As good
> as the documentation is, the code is also well organized and uses a
> lot of good pythonic idioms if you're new to the language.
>
> Jon.
>
> On Dec 1, 6:49 am, martyn <[EMAIL PROTECTED]> wrote:
>
> > David,
>
> > +1 for decorator.
> > That let you use it or not in each view.
>
> > On Dec 1, 9:30 am, David Shieh <[EMAIL PROTECTED]> wrote:
>
> > > Thanks , David Zhou , I will find some information for decorator
> > > And also , I will surf for middleware .
>
> > > Thank you very much , Malcolm.
>
> > > On Dec 1, 3:55 pm, "David Zhou" <[EMAIL PROTECTED]> wrote:
>
> > > > On Mon, Dec 1, 2008 at 2:23 AM, David Shieh <[EMAIL PROTECTED]> wrote:
> > > > > I dont' know whether this make any sense .
> > > > > Right now , I can't test it , but if django won't initiate the
> > > > > views.py as a class , this method will make no sense.
>
> > > > Why not write a decorator?
>
> > > > ---
> > > > David Zhou
> > > > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



django-admin makemessages - excluding folders

2008-12-01 Thread Aljosa Mohorovic

i usually use svn:externals to add django, extensions, evolution and
other stuff to my projects but when i use makemessages in this
situation it generates locale for everything in current folder.
i've added some code to makemessages to enable excluding folders by
pattern to resolve my current situation:
$ django-admin makemessages  -l hr --exclude_regex="^\.\/(django|
photologue)"

i'm sure that there is a better way (since this introduces problems
when i update django), any tips?

Aljosa Mohorovic

svn diff:
Index: core/management/commands/makemessages.py
===
--- core/management/commands/makemessages.py(revision 9538)
+++ core/management/commands/makemessages.py(working copy)
@@ -43,7 +43,7 @@
 # trick xgettext to parse them as Python files)
 return set([x for x in ext_list if x != '.py'])

-def make_messages(locale=None, domain='django', verbosity='1',
all=False, extensions=None):
+def make_messages(locale=None, domain='django', verbosity='1',
all=False, extensions=None, exclude_regex=None):
 """
 Uses the locale directory from the Django SVN tree or an
application/
 project to process all
@@ -114,7 +114,15 @@
 for (dirpath, dirnames, filenames) in os.walk("."):
 all_files.extend([(dirpath, f) for f in filenames])
 all_files.sort()
+
+if exclude_regex != None:
+  exclude_pattern = re.compile(exclude_regex)
 for dirpath, file in all_files:
+if exclude_regex != None:
+  if exclude_pattern.match(dirpath) != None:
+print 'Excluding folder: ', dirpath
+continue
+
 file_base, file_ext = os.path.splitext(file)
 if domain == 'djangojs' and file_ext == '.js':
 if verbosity > 1:
@@ -199,6 +207,7 @@
 make_option('--verbosity', '-v', action='store',
dest='verbosity',
 default='1', type='choice', choices=['0', '1', '2'],
 help='Verbosity level; 0=minimal output, 1=normal output,
2=all output'),
+make_option('--exclude_regex', default=None, help='To exclude
folder(s) provide regex.'),
 make_option('--all', '-a', action='store_true', dest='all',
 default=False, help='Reexamines all source code and
templates for new translation strings and updates all message files
for all available languages.'),
 make_option('--extension', '-e', dest='extensions',
@@ -219,6 +228,7 @@
 verbosity = int(options.get('verbosity'))
 process_all = options.get('all')
 extensions = options.get('extensions') or ['html']
+exclude_regex = options.get('exclude_regex')

 if domain == 'djangojs':
 extensions = []
@@ -228,4 +238,4 @@
 if '.js' in extensions:
 raise CommandError("JavaScript files should be examined
by using the special 'djangojs' domain only.")

-make_messages(locale, domain, verbosity, process_all,
extensions)
+make_messages(locale, domain, verbosity, process_all,
extensions, exclude_regex)

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



How to return Admin to previous filters after save?

2008-12-01 Thread cyberjack

I have an admin interface managing a few thousand records. Finding a
record requires heavy use of multiple list_filter selections. However,
once a user edits a record, the admin interface redirects to the root
admin URL and loses the filter state.

Is there an easy way to have the admin editor return to the calling
URL after a form submit?

 Ie, I'd like the Admin tool to redirect to
   /admin/app/?is_active__exact=0__exact=A__exact=B
instead of
  /admin/app/?

As a work-around, I have my users bookmark common filter
configurations, but it's still pretty frustrating. I feel like there
must be some way to customize the Admin save function, but I don't
know where to start.

Thanks,

-Josh
--~--~-~--~~~---~--~~
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: Form POST Issue

2008-12-01 Thread Karen Tracey
In the future, if you click "Switch to copy-and-paste-view" and then just
copy and paste the contents of the traceback window, that is generally
easier to deal with.  The traceback in your screenshot (which shows your
photosapp/views.py on line 104 calling paginator.page) doesn't match up with
the code you originally showed (where I don't see any call to
paginator.page) so it's a little hard to be entirely sure what is going
wrong.  I'd guess you are passing in a unicode value from the POST data and
the paginator is expecting an integer.  So if you cast your value to an int
before handing it to the Paginator that may fix it.  Possibly the Paginator
should handle this more gracefully, but I'm not sure since I don't have a
full idea of what you code is doing, exactly, and I'm traveling so don't
have time to try to replicate the error myself at the moment.

Karen

--~--~-~--~~~---~--~~
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: Is the initial value of a form field available in the template?

2008-12-01 Thread DavidA

> I think the basic issue is that there are some fields in the object
> that I'd like to display but not have editable, and it's not at all
> clear to me how to make that happen in the form processor. The values
> are dynamic, so they can't be in the template.

I often have this need so I created a custom widget where I just set
the readonly attribute on a TextInput widget:

class LabelWidget(forms.TextInput):
def __init__(self, *args, **kwargs):
attrs = kwargs.get('attrs', {})
attrs['readonly'] = True
if 'class' in attrs:
attrs['class'] = attrs['class'] + ' label'
else:
attrs['class'] = 'label'
super(LabelWidget, self).__init__(*args, **kwargs)

Then I use it in forms like this:

class AccountForm(forms.Form):
name = forms.CharField(widget=LabelWidget)
business = forms.CharField(widget=LabelWidget(attrs={'size': 5}))
...

I set/add 'label' to the CSS class so I can style these differently. I
used a custom widget over explicit "form.initial['field']" syntax in
my template so I could let the form lay itself out automatically
treating all fields the same way.

-Dave

On Dec 1, 1:45 pm, ChrisK <[EMAIL PROTECTED]> wrote:
> > I think you really need to explain what the real problem is that you're
> > trying to solve, because you're asking a question that is too specific.
>
> Fair enough. It's been several days, so I had to dredge a bit to
> remember :-)
>
> I think the basic issue is that there are some fields in the object
> that I'd like to display but not have editable, and it's not at all
> clear to me how to make that happen in the form processor. The values
> are dynamic, so they can't be in the template.
>
> I'm happy not to replicate the logic inside BoundField.as_widget(), if
> there's some way that the "correct" value is exposed to the
> template...
--~--~-~--~~~---~--~~
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: typo in the Django book

2008-12-01 Thread James Bennett

On Mon, Dec 1, 2008 at 3:05 PM, coldlight <[EMAIL PROTECTED]> wrote:
> Another one: in the file

Please don't do this; this is not the errata mailing list for "The
Definitive Guide to Django", it is the mailing list for discussion of
and by users of Django, and every time you post a message here you are
putting something into nearly *12,000* people's inboxes.

If you look at the online version of the book you'll see that it's
possible to click in the left-hand side of any paragraph to pop open a
window wherein you can leave comments; that's likely the best place to
put them.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: typo in the Django book

2008-12-01 Thread coldlight

Another one: in the file

http://new-media.djangobook.com/content/en/1.0/chapter03/404.png

there listed ^/now$, but the book used ^/time$ instead.
--~--~-~--~~~---~--~~
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: Receiving xml via HTTP POST

2008-12-01 Thread Daniel Roseman

On Dec 1, 12:48 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2008-11-30 at 01:15 -0800, Daniel Roseman wrote:
>
> [...]
>
> > No doubt someone will correct me if I'm wrong, but I don't think there
> > *is* any other way of receiving a file via POST except via a form.
>
> You gave an answer, so it's going to look crabby to say this, but that
> isn't correct. You can send anything in the body of an HTTP POST request
> and Django will be able to work with it. What you cannot do is use
> request.POST to access the data, since that does form-decoding. Instead,
> use request.raw_post_data, which is the unprocessed input data (and
> check request.METHOD to see which method was used to submit the data --
> POST, PUT, etc).
>
> Regards,
> Malcolm

No problem Malcolm - it's always good to be corrected. And I didn't
know about request.raw_post_data, so that's two things I've learned
today...
--
DR.
--~--~-~--~~~---~--~~
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: Database model fields question

2008-12-01 Thread Daniel Roseman

On Dec 1, 6:48 pm, sned <[EMAIL PROTECTED]> wrote:
> Is there a way to tell django to use a specific function when
> selecting data from a model?
>
> The sql is relatively simple, but I don't know how to convert that to
> model syntax.
>
> Here's the issue:  a table I'm working with stores ip addresses as a
> 10 digit integer.  To get the ip address out of that, the sql is
> simply SELECT inet_ntoa(ip_field) FROM tbl;
>
> I'm assuming there's some way to tell django to do that cast in the
> model:
>
> class tbl(models.Model)
>     ip_field = models.IntegerField(  what do i do here? )
>
> Anyone have an idea?
>
> Thanks!
> -sned

AFAIK you can't easily define custom SQL to be used when getting a
field from the database. One approach might be to create a custom
model field[1], and override the to_python method to do the inet_ntoa
call in Python[2] (and similarly use the db_prep_save method to
convert back using inet_aton).

[1] Full instructions for custom model fields:
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/

[2] Python's socket module actually converts to and from packed
strings, you need struct.pack/unpack to get to and from integers. See
a recipe here: http://code.activestate.com/recipes/66517/

--
DR


--~--~-~--~~~---~--~~
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: How can I use more than 24 hours in TimeField?

2008-12-01 Thread julianb

On Dec 1, 11:03 am, "K*K" <[EMAIL PROTECTED]> wrote:
> As you know time data type in mysql allow to be used more than 24
> hours, but when there is a more  than 24 hours record in the table
> such as 72:00:00, and then query the table with Django ORM, it will
> report 'ValueError hour must be in 0..23'.
>
> I'm porting a old program that record rum times of the machines to
> Django, so 24 hours is not enough for my new program.
>
> How can I resolve it ?

What you want is probably an integer field, to store the run time in
seconds.
A TimeField is for the time of the day, so that's why the hour can't
be larger than 23.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Using % with psycopg2

2008-12-01 Thread Siah

Hi,

The following code fails on windows, and works just fine on my unix
box. To fix the problem in windows, I must replace('%', '%%') so its
internal string formatting doesn't fail on me. Should I file this bug
for psycopg2?

from django.db import connection
cursor=connection.cursor()
cursor.execute("select '%';")
print cursor.fetchall()

Thanks,
Sia
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model similar to a spreadsheet

2008-12-01 Thread Stefan

Hello,

I'm new to Django and have some problems on how to create the models.

What I want to do is something similar to a spreadsheet, but with more
than one data field per intersection.

Basically like this: (http://dpaste.com/hold/95128/)

Items/Members: Person_A | Person_B | Person_C
Item_1: x=1,y=3 | x=4,y=2 | x=7,y=5
Item_2: x=8,y=2 | x=2,y=0 | x=8,y=4
Item_3: x=4,y=9 | x=5,y=9 | x=3,y=1
.
.
(and so on)

This is the most I could figure out so far (I know, it's almost
nothing): http://dpaste.com/hold/95127/

The main problems are the x= and y= for the items, because each item
has a lot of x and y, namely one x and one y for each person.

I also don't understand if I need to use the ForeignKey in Item and
Person referring to the CostSheet or the ManyToManyField in the
CostSheet referring to Item and Person or even both.

Thanks for your help.

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



Database model fields question

2008-12-01 Thread sned

Is there a way to tell django to use a specific function when
selecting data from a model?

The sql is relatively simple, but I don't know how to convert that to
model syntax.

Here's the issue:  a table I'm working with stores ip addresses as a
10 digit integer.  To get the ip address out of that, the sql is
simply SELECT inet_ntoa(ip_field) FROM tbl;

I'm assuming there's some way to tell django to do that cast in the
model:

class tbl(models.Model)
ip_field = models.IntegerField(  what do i do here? )

Anyone have an idea?

Thanks!
-sned

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



typo in the Django book

2008-12-01 Thread coldlight

I have just start to read the on-line Django book.I don't know whether
this is the best place to report  typos, or whether typos are expected
to be reported at all. But here is one, at

http://www.djangobook.com/en/1.0/chapter03/

in the small selection of the regular expression table, the following
line has a typo,

"?  Zero or more of the previous expression (e.g., \d* matches zero or
more digits)"

where "?" may be a "*".

Best,
coldlight

--~--~-~--~~~---~--~~
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: Is the initial value of a form field available in the template?

2008-12-01 Thread ChrisK


> I think you really need to explain what the real problem is that you're
> trying to solve, because you're asking a question that is too specific.

Fair enough. It's been several days, so I had to dredge a bit to
remember :-)

I think the basic issue is that there are some fields in the object
that I'd like to display but not have editable, and it's not at all
clear to me how to make that happen in the form processor. The values
are dynamic, so they can't be in the template.

I'm happy not to replicate the logic inside BoundField.as_widget(), if
there's some way that the "correct" value is exposed to the
template...


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



Custom inline form

2008-12-01 Thread mrsource


In the inline model option I have overriden the inline form with a
custom form where I only added a choices widget, now the validation
has a wrong behaviour...more precisely if I have set extra property to
2 in inline model options, when I click "Save" django try to validate
even the two empty extra inline model that I have left blank and show
an error like "the primary key field must not be empty"... If I remove
my custom form all is ok.

How can I avoid this validation on the empty extra filed?
--~--~-~--~~~---~--~~
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: printing from the admin?

2008-12-01 Thread David Zhou

On Mon, Dec 1, 2008 at 7:33 AM, Nitzan Brumer <[EMAIL PROTECTED]> wrote:
> I have a class called customers which generates in the admin some kind of a
> "phone book".
> I want to allow the user to print all the records using a print button.
>
> I guess I can do it with a custom CSS file but I hope there is a simple way.
> Is there?

If you want the layout to be print optimized, the easiest way is going
to be using some custom admin templates that use some custom CSS.

-- 
---
David Zhou
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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: Receiving xml via HTTP POST

2008-12-01 Thread chefsmart

Daniel Roseman suggests a very simple and easy to implement solution.
Malcolm Tredinnick explained the usage of request.POST and
request.raw_post_data. I think I would like to keep it pure and go
towards implementing django views that will access and process
request.raw_post_data. The AIR app will do an HTTP POST that will
contain xml in the body of the message.

Just wondering, if this were to be done purely in django, how would
one go about doing a pure HTTP POST request through a django template?
Or am I confusing two tangentially separated ideas?

Regards.

On Dec 1, 5:48 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2008-11-30 at 01:15 -0800, Daniel Roseman wrote:
>
> [...]
>
> > No doubt someone will correct me if I'm wrong, but I don't think there
> > *is* any other way of receiving a file via POST except via a form.
>
> You gave an answer, so it's going to look crabby to say this, but that
> isn't correct. You can send anything in the body of an HTTP POST request
> and Django will be able to work with it. What you cannot do is use
> request.POST to access the data, since that does form-decoding. Instead,
> use request.raw_post_data, which is the unprocessed input data (and
> check request.METHOD to see which method was used to submit the data --
> POST, PUT, etc).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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: Multi Table Inheritance with Mulitple Children

2008-12-01 Thread tofergus

On 01.12-07:59, Fergus wrote:
[ ... ]
> > bit worrying that you consider the traceback to be 'gumph' ...
> 
> Gumph in the sense that it didn't seem awfully relevant in this case,
> as the exception was reasonably self-explanatory. I'm very grateful
> for Python's stack trace in other circumstances, though I've found
> that there are cases where Django magic seems to make the errors and
> the stack more confusing than I think they ought be.

i'm sure you're right but, as you know, it's very difficult for
external parties (i.e. the list) to have faith in that ... generally
better to include such things ... at least in my opinion.
... and that's what counts ! ;-)

[ ... ]
> > there are a couple of ways to munge the logic to make it work but i'm
> > sure you'll figure out what's best for your own scenario.
> 
> My just-tried hack involves dumping the values of the Person object
> into the new User too. I'm surprised there isn't a more clean and
> correct way of doing it though, given that I'm probably going to cry
> any time I want to create a "created" field in the User table!

i'd suggest the 'correct' way to transform an object is to create
the relevant functions within one or t'other.  for example, defining
an object instantiation function for 'User' that takes a 'Person'
object as a constructing argument, or depending on your "world view"
perhaps a 'make_me_user' function for 'Person' but as you have pointed
out above, there's a number of ways to skin the cat.

ps: no idea where the 'created' field is coming from, i've not seen
it before

--~--~-~--~~~---~--~~
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: Overwriting Django Authentication / Session Logic

2008-12-01 Thread Alex Koshelev
Have you read this -
http://docs.djangoproject.com/en/dev/topics/auth/#other-authentication-sources?


On Mon, Dec 1, 2008 at 19:02, Devye <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I am trying to integrate a Django app with an in-house developed
> webapp. The biggest hurdle is to consolidate the two sets of users
> data and session mechanism. I was wondering if it is easy in Django to
> customize the authentication logic and session logic? If so, how would
> I go about it?
>
> I did try to search hints online, but nothing really useful came up.
> Any pointers would be appreciated.
>
> >
>

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



Overwriting Django Authentication / Session Logic

2008-12-01 Thread Devye

Hi,

I am trying to integrate a Django app with an in-house developed
webapp. The biggest hurdle is to consolidate the two sets of users
data and session mechanism. I was wondering if it is easy in Django to
customize the authentication logic and session logic? If so, how would
I go about it?

I did try to search hints online, but nothing really useful came up.
Any pointers would be appreciated.

--~--~-~--~~~---~--~~
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: djangobook.com, chapter 5, __init__() got an unexpected keyword argument 'maxlength'

2008-12-01 Thread djan

Thank you all! This did the trick, and I'm sure it will help be avoid
future problems.

On Dec 1, 9:57 am, Praveen <[EMAIL PROTECTED]> wrote:
> write max_length instead of maxlength
>
> On Dec 1, 1:01 pm, Roland van Laar <[EMAIL PROTECTED]> wrote:
>
> > djan wrote:
> > > Hello,
>
> > > I'm following along with djangobook.com, and I have a problem in
> > > chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> > > 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> > > with MySQL).
>
> > > 
> > >   File "$HOME/djcode/mysite/books/models.py", line 3, in 
> > >     class Publisher(models.Model):
> > >   File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
> > >     name = models.CharField(maxlength=30)
> > > TypeError: __init__() got an unexpected keyword argument 'maxlength
>
> > The book is a bit outdated, maxlength should become max_length
> > please do read:http://docs.djangoproject.com/en/dev/
> > and:http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
> > for more information about django and the changes in 1.0
>
> > Regards,
>
> > Roland van Laar
--~--~-~--~~~---~--~~
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: Multi Table Inheritance with Mulitple Children

2008-12-01 Thread Fergus

On Dec 1, 3:48 pm, ttw <[EMAIL PROTECTED]> wrote:
> bit worrying that you consider the traceback to be 'gumph' ...

Gumph in the sense that it didn't seem awfully relevant in this case,
as the exception was reasonably self-explanatory. I'm very grateful
for Python's stack trace in other circumstances, though I've found
that there are cases where Django magic seems to make the errors and
the stack more confusing than I think they ought be.

> the error says specifically that the 'created' column cannot be null,
> it sounds like your DB and model are out of sync.

I'd just done a manage.py flush, so I'm guessing DB vs model was all
in order.

> there are a couple of ways to munge the logic to make it work but i'm
> sure you'll figure out what's best for your own scenario.

My just-tried hack involves dumping the values of the Person object
into the new User too. I'm surprised there isn't a more clean and
correct way of doing it though, given that I'm probably going to cry
any time I want to create a "created" field in the User table!

Cheers anyhow!

> On Nov 30, 1:24 pm, Fergus <[EMAIL PROTECTED]> wrote:
>
> > I have an inheritance system for defining people.
>
> > So there's a class Person, and sub-class User thus:
>
> > class Person(models.Model):
> >     ''' A person! '''
>
> >     firstname = models.CharField("first name", max_length = 128,
> > help_text = "(required)")
> >     lastname = models.CharField("last name", max_length = 128,
> > help_text = "(required)")
> >     email = models.EmailField("email address", unique = True,
> > help_text = "(required)")
> >     groups = models.ManyToManyField(Group, blank = True, through =
> > 'Membership', related_name = 'group_set', verbose_name = "group
> > memberships")
>
> >     created = models.DateTimeField(auto_now_add = True)
> >     last_modified = models.DateTimeField(auto_now = True)
>
> > class User(Person):
> >     ''' Persons who are also users '''
>
> >     password = models.CharField(max_length = 40, blank = True,
> > editable = False)
>
> > I would like to add child classes after previously having an object as
> > only a parent - so at some point in time a Person can become a User.
> > So I try this in the manage.py shell:
>
> > >>> from MyPidge.Users.models import Person, User
> > >>> myuser = Person.objects.create(firstname = "Fergus", lastname = 
> > >>> "Ferrier", email = "[EMAIL PROTECTED]")
> > >>> myuser.save()
>
> > After myuser.save() there is a Person row in the DB, and all appears
> > well.
>
> > >>> newu = User(password = "hello")
> > >>> newu.person_ptr_id = myuser.id
>
> > [ also tried person = myuser and person_ptr = myuser]>>> newu.save()
>
> > ... Traceback gumph ...
> > Warning: Column 'created' cannot be null
>
> > There is no User row, and the Person row now has blank values except
> > for the last modified field.
>
> > Please tell me if I've done something totally crazy. I only want to
> > add children after-the-fact...
>
> > Many thanks,
> > Ferg
--~--~-~--~~~---~--~~
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: Displaying items of a linked object in a template

2008-12-01 Thread bruno desthuilliers

On 1 déc, 14:20, Daniel Roseman <[EMAIL PROTECTED]> wrote:
> On Dec 1, 12:15 pm, Marco <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello,
>
> > I have this in my models.py :
>
> > class Device(models.Model):
> > name = models.CharField(max_length=30)
>
> > class DeviceProperty(models.Model):
> > key = models.CharField(max_length=30)
> > value = models.CharField(max_length=80)
> > device = models.ForeignKey(Device)
>
> > In my views.py, I'm doing :
> > deviceList = Device.objects.all() and put this list to the response
>
> > In my template, I'm currently displaying the items like this :
> > {% for device in deviceList %}
> >   {{ device.name }}
> >   ...
> > {% endfor %}
>
> > My question is : how can I also display items from my DeviceProperty
> > class ? Like it is described in the model, I have a list of
> > DeviceProperty for each Device. So inside of my "for" loop, I'd like
> > to display the associated DeviceProperty items.
>
> > Any idea ?
>
> > Thanks.
>
> Just carry on with the same logic.
>
> {% for device in deviceList %}
>   {{ device.name }}
>   {% for property in device.deviceproperty_set.all %}
>   {{ property.key }}: {{ property.value }}
>   {% endfor %}
> {% endfor %}

And eventually change your view to:

 deviceList = Device.objects.all().select_related()

(this should avoid one extra db query per property)


--~--~-~--~~~---~--~~
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: Multi Table Inheritance with Mulitple Children

2008-12-01 Thread ttw

bit worrying that you consider the traceback to be 'gumph' but since
the error says specifically that the 'created' column cannot be null,
it sounds like your DB and model are out of sync.

as for the actual problem, you'll have to appreciate that creating a
'User' also creates a 'Person', who's attributes are blank.  when you
alter the parent id you're invsivibly altering the reference to that
new 'Person' and when the systems checks to see if it's changed it
saves the new person (with blank values) over the existing one.
essentially, you have to realise that you are not creating a new
'User'.

there are a couple of ways to munge the logic to make it work but i'm
sure you'll figure out what's best for your own scenario.

On Nov 30, 1:24 pm, Fergus <[EMAIL PROTECTED]> wrote:
> I have an inheritance system for defining people.
>
> So there's a class Person, and sub-class User thus:
>
> class Person(models.Model):
> ''' A person! '''
>
> firstname = models.CharField("first name", max_length = 128,
> help_text = "(required)")
> lastname = models.CharField("last name", max_length = 128,
> help_text = "(required)")
> email = models.EmailField("email address", unique = True,
> help_text = "(required)")
> groups = models.ManyToManyField(Group, blank = True, through =
> 'Membership', related_name = 'group_set', verbose_name = "group
> memberships")
>
> created = models.DateTimeField(auto_now_add = True)
> last_modified = models.DateTimeField(auto_now = True)
>
> class User(Person):
> ''' Persons who are also users '''
>
> password = models.CharField(max_length = 40, blank = True,
> editable = False)
>
> I would like to add child classes after previously having an object as
> only a parent - so at some point in time a Person can become a User.
> So I try this in the manage.py shell:
>
> >>> from MyPidge.Users.models import Person, User
> >>> myuser = Person.objects.create(firstname = "Fergus", lastname = 
> >>> "Ferrier", email = "[EMAIL PROTECTED]")
> >>> myuser.save()
>
> After myuser.save() there is a Person row in the DB, and all appears
> well.
>
> >>> newu = User(password = "hello")
> >>> newu.person_ptr_id = myuser.id
>
> [ also tried person = myuser and person_ptr = myuser]>>> newu.save()
>
> ... Traceback gumph ...
> Warning: Column 'created' cannot be null
>
> There is no User row, and the Person row now has blank values except
> for the last modified field.
>
> Please tell me if I've done something totally crazy. I only want to
> add children after-the-fact...
>
> Many thanks,
> Ferg
--~--~-~--~~~---~--~~
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: GeoDjango question about US zipcode lookup and spatial query

2008-12-01 Thread Justin Bronn

> Thanks Justin, I was using MySQL and it looks like I do need Postgres to get
> the best gis support.
> Do people normally switch their DB backend entirely or do they start a new
> project for geo stuff and connect the main site to this as a separate
> backend? I can see the pros and cons of each approach. Just want to hear
> about people's experience
>

Prior to writing geographic web apps I was a heavy MySQL user.  While
I initially learned Postgres to just use PostGIS, I've personally
found it to be more robust, stable, and an overall better database
than MySQL.  Thus, I ended up switching my backend entirely -- I can't
speak for others, but I've heard of GeoDjango users switching after
finding MySQL's GIS offerings to be inadequate.

However, there's nothing to stop you from having a PostGIS site that
serves up geographic content via a RESTful interface to a MySQL-
powered app.

> 1. There's no 08544 zipcode after the layer mapping. 08544 should point to
> Princeton NJ.

The data in the shapefile is from the 2000 census -- thus, it may not
include recent ZIP code additions.  I believer there are commercial
providers of up-to-date datasets, but I don't know any off-hand.

> 2. I do see 08540 and 08542. 08542 seems correct but 08540 shows North
> Pole??

Both 08540 and 08542 appear properly over Princeton, NJ in my admin.

> Let say I want to do something similar to your example of HoustonCrimeMap,
> and I use Geopy to perform the geocoding to get back the (lat, lon) for each
> crime event location and I also want to show the events within a certain
> radius R from a point P. Do you store the lat lon as a Point for each event
> and construct a polygon of a circle(P,R) and check if the event point is
> contained inside the polygon?

For HCM, each crime has a FK to an address model, which in turn has
the PointField.

There's two ways you can do this:

1.  Use the existing distance lookup API to find the events:

  >>> from django.contrib.gis.measure import D
  >>> from django.contrib.gis.geos import Point
  >>> P = Point(lon, lat, srid=4326) # X, Y (lon, lat), NOT (lat, lon)
  >>> qs = Crime.objects.filter(address__point__distance_lte=(P, D
(km=50)))

Assuming the PointField is using 4326, this is OK and GeoDjango will
use the the PostGIS `ST_distance_sphere` routine in its query to find
all crimes within 50km of the point `P`.  However, for geometry fields
other than PointField that use a geographic coordinate system (e.g.,
those that use angular units of latitude/longitude like WGS84
(srid=4326)) then this query will not work because PostGIS does not
support spherical distance queries on non-point geometries.

2.  Create a buffer from point P with radius R


  >>> from django.contrib.gis.geos import Point
  >>> P = Point(-74.65613, 40.34380, srid=4326)
  >>> P.transform(2824)
  >>> buf = P.buffer(2000.0)
  >>> qs = Crime.objects.filter(address__point__intersects=buf)

Here I'm creating a point centered on Princeton in WGS84.  Next I
transform it to a projected coordinate system for New Jersey
(srid=2824) [1] that has its units in meters.  Finally, I create a
2000 meter buffer around that point and use it to query the database
(the buffer will be implicitly transformed at the SQL level by
GeoDjango).

Regards,
-Justin

[1] http://spatialreference.org/ref/epsg/2824/
--~--~-~--~~~---~--~~
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: Does Django have a function that can be called by every view function ?

2008-12-01 Thread Jon Loyens

Another +1 for decorators.  In fact, the example David S uses
authentication and logins as an example of what he wants to do and its
already handled as a decorator thus giving him a decent pattern to
follow.  David S, I'd suggest you look up the @login_required
decorator and even look through the Django code to see how it's
implemented.  Don't be afraid of cruising through the code.  As good
as the documentation is, the code is also well organized and uses a
lot of good pythonic idioms if you're new to the language.

Jon.

On Dec 1, 6:49 am, martyn <[EMAIL PROTECTED]> wrote:
> David,
>
> +1 for decorator.
> That let you use it or not in each view.
>
> On Dec 1, 9:30 am, David Shieh <[EMAIL PROTECTED]> wrote:
>
> > Thanks , David Zhou , I will find some information for decorator
> > And also , I will surf for middleware .
>
> > Thank you very much , Malcolm.
>
> > On Dec 1, 3:55 pm, "David Zhou" <[EMAIL PROTECTED]> wrote:
>
> > > On Mon, Dec 1, 2008 at 2:23 AM, David Shieh <[EMAIL PROTECTED]> wrote:
> > > > I dont' know whether this make any sense .
> > > > Right now , I can't test it , but if django won't initiate the
> > > > views.py as a class , this method will make no sense.
>
> > > Why not write a decorator?
>
> > > ---
> > > David Zhou
> > > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



testing template tags

2008-12-01 Thread Richard Szopa

Hello,

I have written some doctests for my custom template tags, but
`manage.py test my_app' doesn't seem to notice it. There is an
__init__.py file in the templatetags directory, but apparently that is
not sufficient.

Thanks in advance,

-- Richard
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Local flavor and admin (zip-code)

2008-12-01 Thread Fabio Natali

Hi everybody!

I'm having difficulties while trying to insert a zip-code field in one
of my models. I'd like to rely upon some italian local flavor stuff,
so to get some validation for free.

Here comes my models.py:

from django.contrib.localflavor.it import forms

class DittaDipendenti(models.Model):
nome = models.CharField(max_length=30)
cap = models.IntegerField("Cap",max_length=5)

class DittaDipendentiAdmin(admin.ModelAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == "cap":
return forms.ITZipCodeField(**kwargs)
else:
return super(DittaDipendentiAdmin, 
self).formfield_for_dbfield(db_field, **kwargs)


I get this error:

Request URL:http://localhost:8000/admin/anagrafiche/dittadipendenti/add/
Exception Type: AttributeError
Exception Value:'module' object has no attribute 'ITZipCodeField'


Anyone who can kindly shed a bit of light on this? Or give me some
tips on the best way to get some zip-code field inside my model? I'll
provided more log/context if needed.

Bye and thanks, Fabio.

-- 
Fabio Natali

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



Full time Django developer wanted in/near Atlanta

2008-12-01 Thread Chris H.

We're looking for a great Django/Python developer to join our small
team at ajc.com.

Check out the job posting at Django Gigs [0] or at Craigslist[1].

Here are some of the benefits to working on our team:

* We're a small team --  but full of great people like Maura [2] and
Zellyn [3]

* Our projects are highly visible -- if you've spent more than a
minute on ajc.com, then I guarantee you've seen one of our
applications or utilities at work.

* The variety of projects -- Range from content publishing tools for
staff and users, to data interactives, to user generated content, to
behind the scenes tools that enhance the site.

* Telecommuting -- As much as we all love working together and getting
a group vibe going, we also spit off during the week to get
distraction free and in the zone.

* Take the train to work -- When we're not telecommuting, we work in
an office that's easy to get to on MARTA

* We get paid to work on and in Django and Python -- That's still
pretty damn cool.

If you're interested or if I can answer any questions for you, please
hit me up at: cheisel at ajc dot com -or- dm cmheisel on Twitter

[0]: http://djangogigs.com/gigs/483/
[1]: http://atlanta.craigslist.org/eng/931884539.html
[2]: http://www.paragiraffe.com/
[3]: http://zellyn.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: urlpatterns question

2008-12-01 Thread Karen Tracey
On Mon, Dec 1, 2008 at 7:42 AM, Earl Lapus <[EMAIL PROTECTED]> wrote:

>
> hi all,
>
> I'm new to django and python. I have a small question about
> urlpatterns and it may sound silly to some so please bear with me.
>
> I noticed a bit of difference between a urlpatterns callback function
> of an admin site from that of an app. The callback function for an app
> requires single quotes while that admin callback function does not.
> Removing the single quotes around the callback function name in an app
> would result in an error -AND- adding single quotes around the
> callback function of the admin site would result in an error.
>
> example,
> ...
> urlpatterns = patterns('',
> (r'^admin/(.*)', admin.site.root),
> (r'^testapp/', 'testproject.testapp.views.index'),
> )
> ...
>
> So, what is the difference between a callback function that is
> enclosed on single quotes from that which is not?
>

Nothing really:

http://docs.djangoproject.com/en/dev/topics/http/urls/#passing-callable-objects-instead-of-strings

Karen

--~--~-~--~~~---~--~~
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: Form POST Issue

2008-12-01 Thread Karen Tracey
On Mon, Dec 1, 2008 at 4:08 AM, please smile <[EMAIL PROTECTED]>wrote:

> Hi All,
>
> I need to pass the "totalItems" value as argument to Paginator(disp,
> totalItems) function
>
> if It is  POST.
>
> But it throws the error
>
> "coercing to Unicode: need string or buffer, int found"
>
>
>  How do I rectify it.
>
> Thanks
>
>
>
>
>  def detail(request, gallery_slug, page=0):
>
> if request.method == 'POST':
>
>  totalItems = request.POST['quantity']
>
>else:
>
>  totalItems = 6
>
> gallery = get_object_or_404(Gallery, slug__iexact=gallery_slug)
>
> disp = Photo.objects.filter(gallery=gallery)
>
> paginator = Paginator(disp, totalItems)
>

The full traceback from the error might help people help you.

Karen

--~--~-~--~~~---~--~~
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: Displaying items of a linked object in a template

2008-12-01 Thread Daniel Roseman

On Dec 1, 12:15 pm, Marco <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have this in my models.py :
>
> class Device(models.Model):
>         name = models.CharField(max_length=30)
>
> class DeviceProperty(models.Model):
>         key = models.CharField(max_length=30)
>         value = models.CharField(max_length=80)
>         device = models.ForeignKey(Device)
>
> In my views.py, I'm doing :
> deviceList = Device.objects.all() and put this list to the response
>
> In my template, I'm currently displaying the items like this :
> {% for device in deviceList %}
>       {{ device.name }}
>       ...
> {% endfor %}
>
> My question is : how can I also display items from my DeviceProperty
> class ? Like it is described in the model, I have a list of
> DeviceProperty for each Device. So inside of my "for" loop, I'd like
> to display the associated DeviceProperty items.
>
> Any idea ?
>
> Thanks.

Just carry on with the same logic.

{% for device in deviceList %}
  {{ device.name }}
  {% for property in device.deviceproperty_set.all %}
  {{ property.key }}: {{ property.value }}
  {% endfor %}
{% endfor %}

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



Displaying items of a linked object in a template

2008-12-01 Thread Marco

Hello,

I have this in my models.py :

class Device(models.Model):
name = models.CharField(max_length=30)

class DeviceProperty(models.Model):
key = models.CharField(max_length=30)
value = models.CharField(max_length=80)
device = models.ForeignKey(Device)

In my views.py, I'm doing :
deviceList = Device.objects.all() and put this list to the response

In my template, I'm currently displaying the items like this :
{% for device in deviceList %}
  {{ device.name }}
  ...
{% endfor %}

My question is : how can I also display items from my DeviceProperty
class ? Like it is described in the model, I have a list of
DeviceProperty for each Device. So inside of my "for" loop, I'd like
to display the associated DeviceProperty items.

Any idea ?

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



urlpatterns question

2008-12-01 Thread Earl Lapus

hi all,

I'm new to django and python. I have a small question about
urlpatterns and it may sound silly to some so please bear with me.

I noticed a bit of difference between a urlpatterns callback function
of an admin site from that of an app. The callback function for an app
requires single quotes while that admin callback function does not.
Removing the single quotes around the callback function name in an app
would result in an error -AND- adding single quotes around the
callback function of the admin site would result in an error.

example,
...
urlpatterns = patterns('',
 (r'^admin/(.*)', admin.site.root),
 (r'^testapp/', 'testproject.testapp.views.index'),
)
...

So, what is the difference between a callback function that is
enclosed on single quotes from that which is not?

Thanks in advance... django is FUN!

-- 
There are seven words in this sentence.

--~--~-~--~~~---~--~~
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: Does Django have a function that can be called by every view function ?

2008-12-01 Thread martyn

David,

+1 for decorator.
That let you use it or not in each view.


On Dec 1, 9:30 am, David Shieh <[EMAIL PROTECTED]> wrote:
> Thanks , David Zhou , I will find some information for decorator
> And also , I will surf for middleware .
>
> Thank you very much , Malcolm.
>
> On Dec 1, 3:55 pm, "David Zhou" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mon, Dec 1, 2008 at 2:23 AM, David Shieh <[EMAIL PROTECTED]> wrote:
> > > I dont' know whether this make any sense .
> > > Right now , I can't test it , but if django won't initiate the
> > > views.py as a class , this method will make no sense.
>
> > Why not write a decorator?
>
> > ---
> > David Zhou
> > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



printing from the admin?

2008-12-01 Thread Nitzan Brumer
I have a class called customers which generates in the admin some kind of a
"phone book".
I want to allow the user to print all the records using a print button.

I guess I can do it with a custom CSS file but I hope there is a simple way.

Is there?

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



Re: Image uploads on media temple (gs) failing

2008-12-01 Thread Adda Badda

Okay, perhaps someone could suggest possible techniques for debugging
file uploads?

On Nov 29, 4:10 pm, Adda Badda <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm having difficulties getting image uploads to work on my
> mediatemple gs hosting as part of an admin system. Occasionally one
> file will sneak through but most fail with this response:
>
> >>Proxy Error
> >>The proxy server received an invalid response from an upstream server.
>
> The image file appears in the right directory but has a file size of 0
> bytes.
>
> Is the error to do with the server timing out waiting for a response?
> I am using sorl-thumbnail but tried a vanilla ImageField and had the
> same results. Any ideas anyone?
>
> Sam
--~--~-~--~~~---~--~~
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: Naming a ForeignKey field in the Admin

2008-12-01 Thread Fabio Natali

The Agregator wrote:
[...]
>   CustomerID = models.ForeignKey(Customer)

> The problem is that I want it to say something else, like "Customer
> Name"

Try with

   CustomerID = models.ForeignKey(Customer, verbose_name="Customer Name")

HTH,

-- 
Fabio Natali

--~--~-~--~~~---~--~~
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: XML templates

2008-12-01 Thread Eric Abrahamsen


On Dec 1, 2008, at 7:51 PM, Vicky wrote:

>
> Can we use XML files as templates instead of HTML?

Anything that comes as a plain text file can be produced by a  
template: HTML, XML, plain text, email, iCAL, source code...

Yours,
Eric


>
> >


--~--~-~--~~~---~--~~
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: Naming a ForeignKey field in the Admin

2008-12-01 Thread Nitzan Brumer
Worked like a charm
Thanks

On Mon, Dec 1, 2008 at 1:50 PM, Fabio Natali <[EMAIL PROTECTED]>wrote:

>
> The Agregator wrote:
> [...]
> >   CustomerID = models.ForeignKey(Customer)
>
> > The problem is that I want it to say something else, like "Customer
> > Name"
>
> Try with
>
>   CustomerID = models.ForeignKey(Customer, verbose_name="Customer
> Name")
>
> HTH,
>
> --
> Fabio Natali
>
> >
>


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



XML templates

2008-12-01 Thread Vicky

Can we use XML files as templates instead of HTML?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Naming a ForeignKey field in the Admin

2008-12-01 Thread The Agregator

Hi

I'm new here - in Django and python, more of a Php and wordpress
myself.
anyway - here is my question, hope someone knows the answer.

I have 2 classes - components and customers. every component has a
field that says whos the related customer. like this:

class Component(models.Model):
 #
  Description = models.CharField(_('Description'),max_length=50,
null=True)
  CustomerID = models.ForeignKey(Customer)
 #

Works great made the tables, made the links - everything is cool.
Now, i wanted to create a list in the admin and used that:

class ComponentAdmin(admin.ModelAdmin):
list_display = ('ComponentID', 'Description', 'CatologNumber',
'Location', 'stock', 'CustomerID')

So, as one can see I gave Description a field name (which is also
translated) but CustomerId doesn't have one.

in the admin it looks good and there is actually a column that says
CustomerID and is sortable.
The problem is that I want it to say something else, like "Customer
Name"

So, I've tried doing that:

def CustomerName(self):
return self.CustomerID
CustomerName.short_description = _('Customer Name')

and changed ComponentAdmin to:

class ComponentAdmin(admin.ModelAdmin):
list_display = ('ComponentID', 'Description', 'CatologNumber',
'Location', 'stock', 'CustomerName')

Now, the title of the column  is indeed Customer Name but the column
is not sortable any more.

So, what can I do? how do i create a title for the column and make it
sortable?

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



different database access

2008-12-01 Thread ReneMarxis

hi

i am new to django and evaluating if i could use it for one new
application.

I did some mal app with django last days and i am impressed :) however
i need some infomation from expirienced developers.

1) Is it possible to connect to more than one database, and beeing
able to use the model-functionality from django?
2) I have to connect to: Oracle/MS-SQL Server/ and postgres/sqlite at
the same time. Anyone having expirience with 
http://code.google.com/p/django-mssql/?

thats all for now.

_tia rene
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Debugging Django with PyDev

2008-12-01 Thread Awad

Hi All,

I've recently just updated my eclipse to Ganymede and Pydev to 1.3.24.
And ever since then, I've been unable to debug any of my Django
Projects.

I've gone through the process of setting up a debug launch
configuration with the "runserver --noreload" argument and yet, after
adding breakpoints, it doesn't seem to be triggering the Debugger.
This includes setting "manage.py" as the main module.

Simple python projects seem to debug fine.

Any ideas why it wouldn't work? Any help will be greatly appreciated.

Awad


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



limiting admin's access on a per site basis

2008-12-01 Thread Evan Reiser
We have multiple django sites using the same database, and have different
admins for each of the django sites who's access we would like to limit on a
per site basis.
I was wondering if anyone had an experience or advice about how to do this.
 I think it would be possible to accomplish by creating our own
authentication system which had a many to many relationship between (staff)
user and site objects, but i was wondering if anyone else had any other
solutions.

I had difficulty searching for discussions about this since "django site
admins" are fairly common keywords in most django discussions, so I
apologize in advance if this has been discussed (recently) on
this discussion group.

Thanks in advance for your advice

-Evan Reiser
GamerNook.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
-~--~~~~--~~--~--~---



How can I use more than 24 hours in TimeField?

2008-12-01 Thread K*K

As you know time data type in mysql allow to be used more than 24
hours, but when there is a more  than 24 hours record in the table
such as 72:00:00, and then query the table with Django ORM, it will
report 'ValueError hour must be in 0..23'.

I'm porting a old program that record rum times of the machines to
Django, so 24 hours is not enough for my new program.

How can I resolve it ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Form POST Issue

2008-12-01 Thread please smile
Hi All,

I need to pass the "totalItems" value as argument to Paginator(disp,
totalItems) function

if It is  POST.

But it throws the error

"coercing to Unicode: need string or buffer, int found"


 How do I rectify it.

Thanks




 def detail(request, gallery_slug, page=0):

if request.method == 'POST':

 totalItems = request.POST['quantity']

   else:

 totalItems = 6

gallery = get_object_or_404(Gallery, slug__iexact=gallery_slug)

disp = Photo.objects.filter(gallery=gallery)

paginator = Paginator(disp, totalItems)

--~--~-~--~~~---~--~~
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: djangobook.com, chapter 5, __init__() got an unexpected keyword argument 'maxlength'

2008-12-01 Thread Praveen

write max_length instead of maxlength

On Dec 1, 1:01 pm, Roland van Laar <[EMAIL PROTECTED]> wrote:
> djan wrote:
> > Hello,
>
> > I'm following along with djangobook.com, and I have a problem in
> > chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> > 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> > with MySQL).
>
> > 
> >   File "$HOME/djcode/mysite/books/models.py", line 3, in 
> >     class Publisher(models.Model):
> >   File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
> >     name = models.CharField(maxlength=30)
> > TypeError: __init__() got an unexpected keyword argument 'maxlength
>
> The book is a bit outdated, maxlength should become max_length
> please do read:http://docs.djangoproject.com/en/dev/
> and:http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
> for more information about django and the changes in 1.0
>
> Regards,
>
> Roland van Laar
--~--~-~--~~~---~--~~
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: Does Django have a function that can be called by every view function ?

2008-12-01 Thread David Shieh

Thanks , David Zhou , I will find some information for decorator
And also , I will surf for middleware .

Thank you very much , Malcolm.

On Dec 1, 3:55 pm, "David Zhou" <[EMAIL PROTECTED]> wrote:
> On Mon, Dec 1, 2008 at 2:23 AM, David Shieh <[EMAIL PROTECTED]> wrote:
> > I dont' know whether this make any sense .
> > Right now , I can't test it , but if django won't initiate the
> > views.py as a class , this method will make no sense.
>
> Why not write a decorator?
>
> ---
> David Zhou
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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: OpenId

2008-12-01 Thread Roland van Laar

Chris wrote:
> I have been looking into using OpenId and I discovered that there are
> to 2 django libraries that handle this: django_openId and
> django_authopenid. Any opinions on the two? Not sure which one I
> should go with.
>   

I depends on what you want to do, be a relying party, i.e. the website 
that needs to authentication,
or the openid provider, i.e. the website that hosts the openidentity.

For the first, you can use both, for the provider you can only use 
django_openid.
I would go for django_openid, for it seems to have a more active 
development.

Regards,

Roland

--~--~-~--~~~---~--~~
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 - processing flatpages problem.

2008-12-01 Thread Grzegorz Szymański

I used DEBUG_PROPAGATE_EXCEPTIONS variable and thanks to this found a bug
in my application.

On Sunday 30 of November 2008 12:22:25 Grzegorz Szymański wrote:
> Thank you for the tip. It works well.
>
> I have problem with processing flat pages.
> When debug is switched to True the error appear in db with following
> content:
>
> Traceback (most recent call last):
>   File
> "/usr/local/lib/python2.6/site-packages/django/core/handlers/base.py", line
> 86, in get_response
> response = callback(request, *callback_args, **callback_kwargs)
>   File "/usr/local/lib/python2.6/site-packages/django/views/static.py",
> line 56, in serve
> raise Http404, '"%s" does not exist' % fullpath
> Http404: "/home/grzegorz/workspace/ghome/src/ghome/../ghome/media/o-mnie"
> does not exist
>
> [30/Nov/2008 12:18:16] "GET /o-mnie/ HTTP/1.1" 200 9733
>
> It seems with debugging enabled flat page is processing successfully
> because page http://127.0.0.1:8080/o-mnie/ is displayed as expected. But
> when debugging is disabled (DEBUG=True) error generated after processing
> above url has the same content and additionally I get "Server Error (500)"
> in browser:
>
> [30/Nov/2008 12:19:04] "GET /o-mnie/ HTTP/1.1" 500 1120
>
> Could someone help with this issue?
>
> On Sunday 30 of November 2008 10:26:51 DIrk Ye wrote:
> > How about use this app:
> >
> > http://code.google.com/p/django-crashlog/
> >
> > It will store error info in db.
> >
> > DIrk
> >
> > On Sun, Nov 30, 2008 at 4:36 PM, Grzegorz Szymański
>
> <[EMAIL PROTECTED]>wrote:
> > > On Sunday 30 of November 2008 09:31:55 Grzegorz Szymański wrote:
> > > > Hi,
> > > > I have no too much experience with django and I have problem with my
> > >
> > > django
> > >
> > > > application.
> > > > When I switch DEBUG variable in settings.py to  True the given url is
> > > > handled correctly and page is displayed as I expect. But when is
> > > > switch DEBUG to False then I get "Unhandled exception error" I tried
> > > > to set
> > >
> > > ADMIN
> > >
> > > > variable to get e-mail notification about this error but it seems not
> > > > working.
> > > >
> > > > I could provide additional information if necessary.
> > > >
> > > > Cheers
> > >
> > > It is django "1.0.1 final" and python 2.6.
> > >
> > > --
> > > Grzegorz Szymański | mailto:[EMAIL PROTECTED] | pgp:0x14A27314
> > > jabber ID: [EMAIL PROTECTED]
> > >
> > > Dzwon tanio do wszystkich!
> > > Sprawdz >> http://link.interia.pl/f1fa7



-- 
Grzegorz Szymański | mailto:[EMAIL PROTECTED] | pgp:0x14A27314
jabber ID: [EMAIL PROTECTED]

Dzwon tanio do wszystkich!
Sprawdz >> http://link.interia.pl/f1fa7


--~--~-~--~~~---~--~~
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: Usage of {% url %}

2008-12-01 Thread Roy

I see, so I cannot use {% url %} in this case. Thanks!



On Dec 1, 3:53 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2008-11-30 at 23:42 -0800, Roy wrote:
> > Hi,
>
> > I have the following in one of my templates:
> > Flag
>
> > But I'm getting a TemplateSyntaxError:
>
> > Caught an exception while rendering: Reverse for 'mysite.comments-
> > flag' with arguments '(, '')'
> > and keyword arguments '{}' not found
>
> > The named url "comments-flag" comes from
> > django.contrib.comments.urls.py:
>
> > url(r'^flag/(\d+)/$',    'moderation.flag',             name='comments-
> > flag'),
>
> This URL pattern only accepts a single parameter (an integer). You are
> passing in two parameters, so it won't match this pattern. The fact that
> your view takes an option second parameter is irrelevant to this
> situation, since Django is only comparing against the regular expression
> pattern.
>
> I'm guessing a little bit, but it looks like (from the name) that you're
> wanting the second parameter to be used as a query string in the
> resulting URL. The "url" template tag cannot construct URLs that use
> querystrings like that. You would need to write your own tag that knew
> to use the first N parameters in a call to reverse() to construct the
> first portion of the URL and then the remaining parameters were used to
> construct the query string.
>
> Regards,
> Malcolm

--~--~-~--~~~---~--~~
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: djangobook.com, chapter 5, __init__() got an unexpected keyword argument 'maxlength'

2008-12-01 Thread Roland van Laar

djan wrote:
> Hello,
>
> I'm following along with djangobook.com, and I have a problem in
> chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> with MySQL).
>   
> 
>   File "$HOME/djcode/mysite/books/models.py", line 3, in 
> class Publisher(models.Model):
>   File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
> name = models.CharField(maxlength=30)
> TypeError: __init__() got an unexpected keyword argument 'maxlength

The book is a bit outdated, maxlength should become max_length
please do read: http://docs.djangoproject.com/en/dev/
and: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
for more information about django and the changes in 1.0

Regards,

Roland van Laar


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