Re: Paginator Overhall

2006-10-16 Thread SmileyChris

On Oct 17, 6:11 pm, "SmileyChris" wrote:
> - #2575 fixes up some of the messy bits (including a few bugs) and adds
> orphaning.
Oh, and it also makes Paginator work with lists/tuples.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Paginator Overhall

2006-10-16 Thread SmileyChris

Just chiming in,

To clarify, I only have two patches regarding pagination:
- #2575 fixes up some of the messy bits (including a few bugs) and adds
orphaning.
- #2576 makes a PaginatorPage object which is useful for self-contained
pages (IMO usual use on a template)

> Trying to account for everybody's particular
> preferences for representing page numbers for "other pages", etc,
> becomes tricky. When I last looked at Chris's enhancement, it wasn't
> immediately clear to me how to resolve all those problems.
Neither of my patches address this (nor make it any more of a problem
than it is now).

On a side note, the one thing I dislike about the current paginator
(and my reason behind PaginatorPage) is that is seems very
un-encapsulated when it hits the template.
I'd rather have one 'paginator' key in my context (a PaginatorPage
object) than having a myriad of related keys: 'paginator_current_page',
'paginator_has_next_page', 'paginator_batch_size', ...


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



7 Habits of Highly effective Person By Stephen Covey: Audio Books

2006-10-16 Thread P K Kothari
Links given for first two parts of audio Books in Audio Book section. Balance parts will be shortly given-- With warm regardsP K KothariDownload PowerPoint Presentation files:  
http://powerpoint-presentation.blogspot.comDownload eBooks:  http://ebook-share.blogspot.
Download Audio books in MP3:  http://audiobook-share.blogspot.comDownload Management Articles: 
http://management-article.blogspot.comDownload Collection Articles: 
http://collection-share.blogspot.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  -~--~~~~--~~--~--~---


Re: psycopg trouble

2006-10-16 Thread Jeremy Dunck

On 10/16/06, juampa <[EMAIL PROTECTED]> wrote:
> So, I run:
>
>  ./configure --with-postgres-includes=/usr/local/pgsql/include
> --with-postgres-lib=/usr/local/pgsql/lib
> --with-mxdatetime-includes=/Library/Frameworks/Python.framework/Versions/2.5/lib/Python2.5/site-packages/mx/DateTime/mxDateTime
> --with-python-version=2.5
>
>
> And I am greeted with:
>
> checking for python...
...
> checking for main in -lcrypt... no
> checking for main in -lcrypto... yes
> checking for PQconnectStart in -lpq... no
> configure: error: can't build without PostgreSQL libraries

Hmm, what does pg_config --libdir return?

http://code.djangoproject.com/wiki/SetupOnTiger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: DB caching - how does Django handle external changes to the DB

2006-10-16 Thread Kenneth Gonsalves


On 16-Oct-06, at 8:49 PM, Stefán Freyr Stefánsson wrote:

> sort of a caching mechanisme that is hard to "turn off", making it  
> vulnerable to not picking up changes to the data that is done by  
> external processes.

it picks up changes made to the data in database - dont think you  
need to worry

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



psycopg trouble

2006-10-16 Thread juampa

Hello out there:
This issue seems to be a recurruing one, but I have been unable to
find a post that solves it. I can't compile psycopg 1.1.21 on my core 2
Duo iMac. For that matter, I can't compile it on a G4 iMac or a G3
iBook. Somehow I managed to compile it in a G4 in the past, but I can't
reproduce it.

For this current iteration I am using Mac OS X 10.4.8. Python 2.5
was installed from a universal package downloaded from the Python site.
I built and installed PostgreSQL 8.1.4 both with and without ssl
(psycopg fails to compile either way). I also installed mxDateTime
2.0.6 successfully.

So, I run:

 ./configure --with-postgres-includes=/usr/local/pgsql/include
--with-postgres-lib=/usr/local/pgsql/lib
--with-mxdatetime-includes=/Library/Frameworks/Python.framework/Versions/2.5/lib/Python2.5/site-packages/mx/DateTime/mxDateTime
--with-python-version=2.5


And I am greeted with:

checking for python...
/Library/Frameworks/Python.framework/Versions/Current/bin/python
checking python version... 2.5
checking python installation prefix...
/Library/Frameworks/Python.framework/Versions/2.5
checking python installation exec_prefix...
/Library/Frameworks/Python.framework/Versions/2.5
checking definitions in Python library makefile... done
checking location of python library...
$(prefix)/lib/python2.5/site-packages
checking location of python shared modules...
$(exec_prefix)/lib/python2.5/site-packages
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking whether make sets $(MAKE)... yes
checking for inline... inline
checking PostgreSQL version... 8.1
checking PostgreSQL type catalog...
/usr/local/pgsql/include/server/catalog/pg_type.h
checking for mxDateTime.h... yes
checking for main in -lcrypt... no
checking for main in -lcrypto... yes
checking for PQconnectStart in -lpq... no
configure: error: can't build without PostgreSQL libraries

I know the postgresql libraries are there (libpq.a, libpq.dylib), so
something else must be causing this. Can anyone help?

Oh, yes: I have also tried setting MACOSX_DEPLOYMENT_TARGET=10.4 and
other variables indicated in the psycopg readme file.

Thanks,

Juampa


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Model Reuse

2006-10-16 Thread Steve Wedig

Alrighty, I've pulled out the relationships into separate separate
models, as shown below. This correctly represents the information.
However, I would like to work with the sets of related threads
directly, rather than always traversing the intermediate models.

I'm not sure how to write the functions where the ???'s appear below.
I'd like to return a lazy QuerySet of threads (so basically pretending
the threads are directly related). I would appreciate any advice on
this matter...

class Thread(models.model):  # threads don't care where they are used

class Location(models.model):
  def thread_set(self):
???
  thread_set = property(thread_set)

class LocationThread(models.model): # m-n relationship
  thread = models.ForeignKey( Thread )
  location = models.ForeignKey( Location)

class Group(models.model):
  def thread_set(self):
???
  thread_set = property(thread_set)

class GroupThread(models.model): # m-1 relationship
  thread = models.OneToOneField( Thread )
  location = models.ForeignKey( Location)

Thanks,
Steve

On 10/16/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Mon, 2006-10-16 at 02:44 -0700, Steve Wedig wrote:
> > I have a thread model that I would like to reuse in multiple places.
> > So a thread should have no knowledge of where it is contained.
> >
> > I also have a group model and a location model. I would like to have
> > multple threads in a group (1-n reln between group and thread). I
> > would also like threads to appear at _multiple_ locations (so a m-n
> > reln between location and thread).
> >
> > I am wondering, what is the best way to accomplish this in django? I
> > am reasonably familiar with the generic relation mechanism, however
> > that appears to only work for 1-n relationships. Plus I don't want to
> > a thread to worry about where/how it is used/contained.
>
> A many-to-many relation is identical to two one-to-many relations put
> back-to-back. Think about how a many-to-many relation is implemented at
> the table level (whether by Django or in any database setup): you have a
> table in the middle that contains pairs of entries, one from each end of
> the many-to-many relation.
>
> So I would think you could create a many-to-many generic relation by
> having an intermediate model that is 1-n to both the thread and location
> models. All the intermediate model does is handle the connection. Note
> that I haven't actually worked out the details, but I can't think of any
> insurmountable problem. If you get stuck implementing this, sing out and
> we should be able to help.
>
> 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
-~--~~~~--~~--~--~---



Re: Modular apps question

2006-10-16 Thread Malcolm Tredinnick

On Mon, 2006-10-16 at 13:37 -0700, Rob Hudson wrote:
> I have a central app that is going to be in all projects.  I have a few
> ancillary apps that may or may not be part of my project.  What I'd
> like to do in my main view code is to see if the app is loaded before I
> invoke a call in that ancillary app.  Would the best bet be to pull in
> settings.INSTALLED_APPS and see if it exists there, then if so, call
> the method in that app that relates to my main app?

Have a look at the django.db.models.loading.get_app() function. This
probably does what you are looking for.

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



Re: doctests and type(_) is bool ?

2006-10-16 Thread Malcolm Tredinnick

On Mon, 2006-10-16 at 21:00 +0200, [EMAIL PROTECTED] wrote:
> Hi Malcolm,
> 
> >
> > Needs more investigation to confirm if this is the case. Ine test would
> > be to explicitly import gettext() as _() in your test file, since that
> > would introduce different aliasing rules for the two cases, I believe.
> >
> from django.utils.translation import gettext as _
> 
> worked fine for me.

Yeah, so that kind of confirms my suspicion. Okay, another bug to fix
when we get time. Thanks for testing it. I've made ticket #2920 for this
so that we don't forget.

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



Re: Re: Django, Postgres and Server Crash

2006-10-16 Thread Malcolm Tredinnick

On Mon, 2006-10-16 at 13:45 -0500, James Bennett wrote:
> On 10/16/06, Mike <[EMAIL PROTECTED]> wrote:
> > The server is rather new. 2GB of memory with a top grade Opteron (not
> > sure which). Once again, the server is running with low load for most
> > of the day, and as much as I want to, I have hard time believing its
> > the server that is to blame.
> 
> FWIW, I wouldn't run a high-traffic DB server on anything less than
> 4-6GB of RAM, and I wouldn't really feel happy until I had 8.

Whilst I know what you're saying, these are the things one needs to
benchmark if you really care about minimums. More memory can never hurt
and, usually, more CPUs aren't a bad thing either. Along with number of
connections, connection creation frequency, database size, query
complexity and result size can all have an effect on the required
numbers (in truly bizarre ways sometimes).

Just for reference, I've had multiple PostgreSQL servers in operation
that handle real-time stock prices and trades from the Hong Kong stock
exchange with 2 GB of RAM and a couple of hundred persistent connections
it ran comfortably for a long time (that system now has a lot more
memory in the database machines, but that's partly because the sweet
spot for pricing came down and we wanted to push out the maximums it
could sustain).

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



Re: adding images to my content

2006-10-16 Thread RajeshD


> > > The admin does not show the full path of the uploaded file, so the end
> > > user would need to fiddle with the path ... trying to smoothen this
> > > process so the url that is displayed in admin is the full path or at
> > > least a path that works.  Or god forbid drag and drop! ;)
> > As a quick fix, in the admin list page for your images, you could add a
> > custom column that does show the correct (Markdown-friendly) path for
> > each image. The user could then cut and paste that path into the
> > Markdown based text where needed.

> Another column in the model that is updated from the other attributes
> of the object ...  sounds like it should do the trick.

Incidentally, I meant to say add a "display column" in the admin list
page through list_display and not add a database column to your model.
Basically, this "display column" would show output of a custom function
that's defined in your model. You could even use get__url in
your list_display directly. See below for more on that.

> It turns out MEDIA_URL is used to render the links for file fields as
> expected, but mine didn't have a trailing slash so was being truncated,
> hence broken.

I see.

 The anchor is rendered like {{ myapp.files.file }}
> which turns out to be something like  href="http://1.2.3.4:8000/media/upload/20060914R4.oak.pdf; >
> upload/20060914R4.oak.pdf .

A better way to render the anchor is to use the get__url
method in your model where fieldname is the name of the FileField. See:
http://www.djangoproject.com/documentation/model_api/#filefield

>
> I think I will change this to
> Tutorials 1-N Sections
> Tutorials 1-N Files
>
> So files can be reused in different sections and both sections and
> files can be edited in one admin screen using edit_inline.
> 

Yes, reuse is a good thing ;)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Don Arbow

On Oct 16, 2006, at 1:30 PM, Rob Hudson wrote:
>
> On Oct 16, 1:00 pm, "Terry" <[EMAIL PROTECTED]> wrote:
>> Easiest way I've found to do it is to add the following as the first
>> two lines of the view function that you want to debug:
>>
>> import pdb
>> pdb.run_trace()
>>
>> Then, when you attempt to load the view, you will get the (pdb)  
>> prompt
>> at your development server, and you can print variables, single step,
>> set breakpoints, etc.
>
> I was trying to see what this did but I get an error that there is no
> run_trace() method in pdb.  In looking at pdb from the Python shell, I
> see this is true.  At least for my Python version (2.3.5).  Did you
> mean another method?  If so, could you explain more?



The method is actually called pdb.set_trace().

Don



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: custom-query or redundant-data, which is worse? :)

2006-10-16 Thread Terry

gabor wrote:

> which way do you chose-usually/recommend?

I would go with the custom query.  This is the DRY principle (see
http://www.djangoproject.com/documentation/design_philosophies/#don-t-repeat-yourself-dry
): don't write down any data more than once.

The exception is when you actually see performance hurting, or you can
prove to yourself that performance is going to hurt.  Then you use a
performance-improving technique.  In this case, the likely technique is
to cache some values, probably exactly those extra values you were
keeping around.  But make it explicit that it's a cache, and make it a
well-behaved cache.  That means that you have ways of detecting when
your cache is no longer valid, and that you can always cope if you
don't have a valid cache.  For your stuff, I would invalidate the cache
whenever a Recipient's save() method is called.  Then, the next time
something needs to find out how many Recipients are pending, it would
recalculate it the expensive way and cache the results for the next
time someone needed it.

- Terry


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: adding images to my content

2006-10-16 Thread RajeshD

>
> The admin does not show the full path of the uploaded file, so the end
> user would need to fiddle with the path ... trying to smoothen this
> process so the url that is displayed in admin is the full path or at
> least a path that works.  Or god forbid drag and drop! ;)
>

As a quick fix, in the admin list page for your images, you could add a
custom column that does show the correct (Markdown-friendly) path for
each image. The user could then cut and paste that path into the
Markdown based text where needed.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



custom-query or redundant-data, which is worse? :)

2006-10-16 Thread gabor

hi,

i'd like to know your opinion about a decision i have to make a lot of 
times while developing with django...

an example:

let's have a system where sometimes we have to send out a LOT of emails.
so we decide to have a periodically running process (cronjob, probably), 
that will check whether there is some mail-sending to do, and if yes, 
will send it out.

let's have the following model:

==

class Task(Model):
begin = DateTime(blank=True,null=True)
end = DateTime(blank=True,null=True)

from_addr = EmailField()
subject = CharField(maxlength=100)
body = TextField()

#these are the important fields
all_recipients = IntegerField()
remaining_recipients = IntegerField()
error_count = IntegerField()



class Recipient(Model):
addr = EmailField()
task = ForeignKey(Task)
done = BooleanField(default=False)
error = CharField(maxlength=100,blank=True)


(if the error-field is an empty string, that means that there were no 
errors)
==


i hope the models are understandable... the mails are sent with the same 
from_addr, subject and body, but to a lot of different recipients.

now please look at the last 3 fields in the Task model. they are clearly 
redundant. they can be easily calculated from the Recipient objects.
so theoretically we could drop those fields (we could even create 
read-only attributes in the Task-model, which would query those values 
in the db)



now imagine a webpage, where i want to list the status of all the Tasks...

one line for every task, and i'd like to show all those numbers for it.
and i do not want to do 3 separate db-queries for every Task object (to 
calculate those "missing-because-redundant" fields)


with custom SQL, i could do it in a constant-number of queries, but not 
with django querysets.

so, i have 2 possibilities:

1. i remove those 3 fields from the Task model (because they are 
redundant), and use a few custom sql-queries in the task-list-view

or

2. i keep those 3 fields, i ignore that they are redundant, and 
everything works nicely with querysets.


which way do you chose-usually/recommend?

p.s: i hope you understand that this is not a critique of django. this 
would happen with any non-native-sql db-api.

thanks,
gabor

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



adding images to my content

2006-10-16 Thread Milan Andric

Hello,

I can serve my static files no problem,
in apache I did 
SetHandler None and an Alias /media
/homedir/djangostuff/myapp/media.

The trick comes in the process or flow of adding files/images into a
body of text.

I'm adding content to the db through the admin and using markdown in
the content for rendering html ... works great.  Now I'd like to add
images to the post , embed them inline:

in markdown that's ![alt text][/my/path/image.jpg "title"]

The admin does not show the full path of the uploaded file, so the end
user would need to fiddle with the path ... trying to smoothen this
process so the url that is displayed in admin is the full path or at
least a path that works.  Or god forbid drag and drop! ;)

I got some hints that the best way to do that would be to use a custom
admin template. admin/myapp/mymodel/change_form.html.

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



Re: Need an advice: simple Online Store project (long)

2006-10-16 Thread Serg Kovrov

No, I wasn't. Thanks for pointing out. Although I didn't found (yet)
anything regarding attributes inheritance, project itself looks
interesting. And it have it's own news group! Perhaps worth to checkout
code...

On Oct 16, 11:35 pm, Steven Armstrong <[EMAIL PROTECTED]> wrote:
> Are you aware of satchmo?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Terry

Rob Hudson wrote:

> I was trying to see what this did but I get an error that there is no
> run_trace() method in pdb.  In looking at pdb from the Python shell, I
> see this is true.  At least for my Python version (2.3.5).  Did you
> mean another method?  If so, could you explain more?

No, that was the method.  I admit that I am using python2.5, but
according to http://www.python.org/doc/2.3.5/lib/module-pdb.html , this
method is in 2.3.5 as well.

- Terry


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Steven Armstrong

On 10/16/06 21:11, Rob Hudson wrote:
> On Oct 16, 11:17 am, Steven Armstrong <[EMAIL PROTECTED]> wrote:
>> A djangofied version of this [1] would be cool.
>>
>> [1]http://pythonpaste.org/screencasts/evalerror-screencast.html
> 
> I agree.  That would be very useful.  One could argue that it should
> only be accessible when running under WSGI.  Would that make it easier
> to implement?
> 

I believe the django dev server runs on top of WSGI. So it shouldn't be 
to difficult to integrate that. I'll have a look at it next time I have 
a moment. Unless someone else beats me to it that is (hint, hint)
  ;)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Modular apps question

2006-10-16 Thread Rob Hudson

I have a central app that is going to be in all projects.  I have a few
ancillary apps that may or may not be part of my project.  What I'd
like to do in my main view code is to see if the app is loaded before I
invoke a call in that ancillary app.  Would the best bet be to pull in
settings.INSTALLED_APPS and see if it exists there, then if so, call
the method in that app that relates to my main app?

To provide some context, I have an app called page and an app called
question.  In some projects there is no need for questions.  Question
has a foreignKey to page.

I have a load_page view that looks for page.question_set.all() but I
only want this called if it's loaded.  If INSTALLED_APPS is the best
way, are there helper functions to check if it exists there or do I
have to iterate and see for myself.

Thanks,
Rob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Need an advice: simple Online Store project (long)

2006-10-16 Thread Serg Kovrov

Hello. I'd like to try to build a simple (I believe) project with
Django - an Online Store. That is, browseble and manageable catalog of
arbitrary goods.


Here is the draft data models for my project.

* Item. Representation of actual goods. Belong to one of the
  Categories. Category defines attributes, which may have values.
  As well inherit attributes from all parent categories.

* Category. Hierarchy tree consist of Category entities. Each of
  categories can have arbitrary set of Attributes.

* Attribute. Simple attribute of a Category. Defines name and type
  (text,  int, bool, etc.). Possibly, can be shared between categories.

* AttributeValue. Concrete value of Attribute. Each belong to
  individual item.


assumptions:

* Parent attributes should be inherited - that's the nature of
  real-world hierarchies.

* Same attributes may be used in different categories not through
  inheritance (that is, many to many relationship). For example car
  audio and computer parts usually does have a brand, but fruits
  usually doesn't.



Example (categories are in '', and attributes are in []):
'root' [name, price]
 |-'electronics' [brand]
 |  |-'car audio'
 |  |  |-'in-dash receivers' [has_removable_panel, plays_mp3]
 |  |  \-'speakers' [power, size]
 |  \-'portable players' [battery_capacity]
 |-'computers' [brand]
 |  |-'workstations' [cpu, ram, hdd]
 |  |-'laptops' [battery_capacity, cpu, ram, hdd]
 |  \-'parts'
 \-'books' [publisher, author, pages]
|-'science fiction'
\-'for kids'

E.g. every Item in 'laptops' Category can have unique AttributeValue
for [name, price, brand, battery_capacity, cpu, ram, hdd] Attribute.


My concerns are:
- how to implement attributes hierarchy (inheritance part) with Django
  models API?
- Is there a way to use built-in admin interface to manage this data?
- There are maybe flaws in assumptions and/or data models for given
  subject. For example I'm not sure if many-to-many relations are best
  for attributes - maybe duplicate attributes could be used instead. Or
  force user to refactor hierarchy to avoid attribute duplications...

Thanks.
-- 
serg.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

John,

Excellent.  The requirement to make it easily sortable makes your
solution compelling. Thanks for detailing. Plus Im sure that there will
lots of places where this type of Signals method would be handy.

MerMer


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread johnnnnnnn

On Sun, Oct 15, 2006 at 01:26:18PM -0700, MerMer wrote:
> I have two Models.
> 
> 1.  Product
> 2.  Review -  There can be many reviews for any product (one -to many
> relationship)
> 
> One of the fields of Review is "Rating". This  holds an integer between
> 1 and 5.
> 
> I want to display a list of Products, and display the average review
> rating for each product.

Other responses have pointed you in the direction of custom
SQL. There's another (less data-normalized) way, which can be
implemented without SQL knowledge: use signals. This also has the
benefit of being easily sortable.

Step one is to add an "average rating" attribute to your Product
model. Set it to default to 0.0, or allow nulls and default to null.

Step two is to create a function (a function, not an object method)
which will update the average rating. That function should take this
argument list:

(sender, instance, signal, *args, **kwargs)

"instance" is the important one here, as it will be a Review
object. Use that to get the Product object, and then calculate the
average rating, set the avg_rating attribute of that Product object,
and call save().

Step three is wiring that function to the signal you
want. Specifically, you probably want the pre_save or post_save
signal, fired from the Review model.

You can do all of this in your models.py, which would end up looking
something like this:

# a bunch of imports
from django.db.models import signals
from django.dispatch import dispatcher

class Product:
# blah blah blah

class Review:
# blah blah blah

def update_average_rating(sender, instance, signal, *args, **kwargs):
# 'instance' will be the Review object being saved
#
# use that to get the Product object affected, calculate the new
# average rating, then call .save() on the Product object

dispatcher.connect(update_average_rating, signal=signals.pre_save, 
sender=Review)

Once you do that, the "average rating" attribute in your Product model
will be updated automatically every time a new Review is created (or
when an old Review is modified).

Do a google search for "django signals" for more information.

-joh

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Terry

code enquest wrote:
> in PhP i used to print_r(array) to see what if got in my array that I
> want to bring on the screen. Smarty even had a popup screen to show this.
>
> How can I see in Django what I got in the view? So that working in the
> template goes a tat faster? What is the print_r($array) in the template
> or Django version?
>
> Enquest

I have found it very useful to fire up the python debugger from inside
the Django development server.

Easiest way I've found to do it is to add the following as the first
two lines of the view function that you want to debug:

import pdb
pdb.run_trace()

Then, when you attempt to load the view, you will get the (pdb) prompt
at your development server, and you can print variables, single step,
set breakpoints, etc.

- Terry


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread Tim Chase

> Any suggestions on how would you get the server to calculate
> and return the average?

Though I believe someone else already answered this, Django 
allows you to fire off live SQL queries, which can do things like

SELECT AVERAGE(column_name1)
FROM tblTable

which will just return the average of the values in column_name1.

Or, if you want summary values base on groups, you can do things like

SELECT column_name1, AVERAGE(column_name2)
FROM tblTable
GROUP BY column_name1

which would return two columns...one for some common aggregate 
value, and one for the average for items having that common 
aggregate value.  E.g.  if your source data looks something like

column_name1  column_name2
John1
John2
John3
Mary5
Mary7
Pat 8

The output would be something like

column_name1  column_name2
John   2
Mary   6
Pat8

(note that only one column_name1 value appears because we're 
grouping on it, and that the value in column_name2 is the average 
of just the values for that person's name).

The result of the first query (that just returns the average) 
would just return (1+2+3+5+7+8)/6

-tkc








--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

Tim,

Many thanks - that has helped me understand alittle more about Python.
 I'm sure that there is a faster way.  It's been more of an exercise
for me to try and get to understand Django, Python etc. I'm practically
a complete newbie.

Any suggestions on how would you get the server to calculate and return
the average?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



DateTime field validation

2006-10-16 Thread plisk

Hi there,

Is it possible somehow to validate DateTime field in admin against
another DateTime field(with validators.IsLessThanOtherField for
example) without writing custom validator ? With
validators.IsLessThanOtherField it complains because of in all_data
DateTime field is splitted to Date and Time and moreover they are
strings, not datetime objects, so as i see now i have to write custom
validator with conversion from date+time strings to datetime objects
and then do comparision. Any clues how it could be done cleaner ?

Alex


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: How the @$$#% can I debug FastCGI errors ?

2006-10-16 Thread James Bennett

On 10/16/06, orestis <[EMAIL PROTECTED]> wrote:
> PLEASE PLEASE someone if you know how to deal with this stuff drop a
> line here.

Set DEBUG=True and look at the error page?

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: doctests and type(_) is bool ?

2006-10-16 Thread dummy

Hi Malcolm,

>
> Needs more investigation to confirm if this is the case. Ine test would
> be to explicitly import gettext() as _() in your test file, since that
> would introduce different aliasing rules for the two cases, I believe.
>
from django.utils.translation import gettext as _

worked fine for me.

Thanks,
Dirk

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



How the @$$#% can I debug FastCGI errors ?

2006-10-16 Thread orestis

This is driving me CRAZY!

The FastCGI logs show nothing (the stupid incomplete headers message).
However, I get my custom FastCGI error page. (internal_error.html).

My site is on and off every 5 minutes, I can't stand it. I've contacted
the host (dreamhost) but I've yet to get an answer.

PLEASE PLEASE someone if you know how to deal with this stuff drop a
line here.

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



Re: Re: Django, Postgres and Server Crash

2006-10-16 Thread James Bennett

On 10/16/06, Mike <[EMAIL PROTECTED]> wrote:
> The server is rather new. 2GB of memory with a top grade Opteron (not
> sure which). Once again, the server is running with low load for most
> of the day, and as much as I want to, I have hard time believing its
> the server that is to blame.

FWIW, I wouldn't run a high-traffic DB server on anything less than
4-6GB of RAM, and I wouldn't really feel happy until I had 8.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Re: Django, Postgres and Server Crash

2006-10-16 Thread James Bennett

On 10/16/06, Mike <[EMAIL PROTECTED]> wrote:
> I just svn update my django directory. Doesn't the latest django
> version reflect all the bug fixes? Do I have to check out
> 0.91-bugfixes?

The "bugfixes" branches are only for the older (0.90 and 0.91)
versions of Django, and I only mentioned them because there are people
still using those versions, and there was a problem in 0.90 and 0.91
which could leak DB connections under mod_python. If you're on 0.95 or
current trunk, you don't have to worry about that.

> Pressing 'c' on top clears everything a little bit. One thing I think I
> forgot to mention is 90% of the time the server load is moderate. It is
> 3 times a week around early in the morning that my django and postgres
> start dancing to death for me. Given that my server hardware handles
> the peak time with no problem, I don't think I need to upgrade the
> server.

As someone else suggested, that really sounds like a cron job or some
other form of maintenance taking you down. What sort of cron stuff do
you have set up?

Another possibility, and one we live with daily at World Online, is
that "early in the morning" is prime time for search indexers; it's
not unusual for us to get concentrated bursts of traffic where Yahoo,
MSN and Google are crawling every page of every one of our sites at
the same time, way late into the night/early in the morning, and that
can generate significant load even though it doesn't seem like "real"
site traffic.

> My guess is that somehow those aggregate builders are not cleaning up
> afterwords that cause the server to start overloading and die after 5
> to 6 hours.

That's another possibility, especially if those processes leave
connections hanging open. In top, look for zombie processes, or
postgres processes which say "idle in transaction" to get a feel for
where those are (but keep in mind that it's normal for a postgres
process to spend some time in the "idle in transaction" state -- it's
only if a particular process gets into an idle state and stays there a
long time that you need to investigate).

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: mod_python help needed

2006-10-16 Thread moberley

doug wrote:
> the flatpages url must be LAST in the list of urls to try- not sure
> why- but that fixed it.

The flatpages pattern must be at the end of the patterns because an
include pattern forwards the entire portion of the url request
following the matched part. The flatpages pattern is an empty string
which means it matches immediately following the example.com/ part and
therefore leaves nothing for the other patterns to match on. I missed
this when I looked at your settings the first time.

Hopefully this explanation makes enough sense to be helpful.

Bradley Peters


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Steven Armstrong

On 10/16/06 17:43, Rob Hudson wrote:
> [EMAIL PROTECTED] wrote:
>> I quite often plug in a nonsense command e.g. "fudge" just to raise the
>> debug page, maybe with a few
> 
> I do the same.  It would be awesome if there were a "debugger" app
> (contrib app anyone?) that we could load in the template:
> 
> {{ debugger }}
> 
> That would show a unobtrusive link that when clicked would open a full
> debug window like the ones on template errors with local variables,
> etc.  I've seen some WSGI presentations where you can even have a
> Python shell with those variables.  That sounds like it takes some work
> to store those but something like this would be very useful for Django.
> 
> -Rob
> 

A djangofied version of this [1] would be cool.

[1] http://pythonpaste.org/screencasts/evalerror-screencast.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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread Tim Chase

>def av_rating(self):
> queryset = self.review_set.all()
> x=0
> y=0
> for rating in queryset:
> x=x+rating.rating
> y=y+1
> return x/y
> 
> {{ objects.av_rating }} is the tag that is then put in the template.
> 
> Can anybody comment on the disadvantage/advantages of using this type
> of custom model method?  Also, if anybody can advise me on how I get
> the division to work - that would also be appreciated - Django returns
> a Zero Division error.

I don't know about the efficiency of calculating this, as you're 
pulling back all the data just to calculate the average over the 
set.  I would suspect it would be faster for the server to simply 
calculate the average and return it (one datum traversing the 
net, rather than a whole dataset).

As for the exception/error, you could do any of a number of things:

1)  return y and x/y or 0

2)

try:
return x/y
else:
return 0

3)
if y == 0:
return 0
else:
return x/y

However, having the server calculate the average should obviate 
the need for such contortions.

HTH,

-tkc






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

 Looking at the options, I've also experimented with creating a custom
Model method.
The following almost works ( The division at the end returns an error
and I'm new at Python so need to work that out)

   def av_rating(self):
queryset = self.review_set.all()
x=0
y=0
for rating in queryset:
x=x+rating.rating
y=y+1
return x/y

{{ objects.av_rating }} is the tag that is then put in the template.

Can anybody comment on the disadvantage/advantages of using this type
of custom model method?  Also, if anybody can advise me on how I get
the division to work - that would also be appreciated - Django returns
a Zero Division error.

MerMer


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Django, Postgres and Server Crash

2006-10-16 Thread Gary Doades

On Monday 16 October 2006 18:01, Mike wrote:
> The server is rather new. 2GB of memory with a top grade Opteron (not
> sure which). Once again, the server is running with low load for most
> of the day, and as much as I want to, I have hard time believing its
> the server that is to blame.

But it just might be.

it is possible to get into a catastrophic behaviour where the load get 
sufficient that pages start to take a little longer to service. This means 
that incoming requests spawn new process because the normal pool of processes 
is busy. This puts more load on the server and so on.

Mostly the bottleneck in these situation is the disk system not the processor. 
As you are also running at high memory load there will be a fair amount of 
swap activity on the disk, leading to the database taking even longer to 
process requests, leading to more processes being spawned. I think you get 
the picture. 

Just because it is a shiny new server with good processors does not always 
mean it is up to the job.

The questions about the server spec, disks in particular are therefore valid. 
Just take a look on the postgres-performance mailing list where you will see 
dozens of threads about this kind of performance problem. You won't always 
see it at peak loads if the peak dies down quickly enough for the disks to 
start serving the database in good time again.

Your problem may or may not have anything to do with the above if you are 
leaking database connections, but it's worth looking into.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Django, Postgres and Server Crash

2006-10-16 Thread Tim Chase

> Pressing 'c' on top clears everything a little bit. One thing
> I think I forgot to mention is 90% of the time the server load
> is moderate. It is 3 times a week around early in the morning
> that my django and postgres start dancing to death for me.
> Given that my server hardware handles the peak time with no
> problem, I don't think I need to upgrade the server.

This sounds like some cron job walking your server off the deep 
end.  I don't know what sort of control you have over the matter, 
but there may be some crazy auto-vacuum process or some similar 
creature that is set to fire at such intervals.

I'd check your crontab (or your /etc/cron.d or your 
/etc/cron.{daily,weekly,monthly} directories) for things postgres 
related (or that would talk to a postgres server).  Or, if it's a 
win32 server, there might be some troublemaker in your list of 
scheduled processes.

-tkc






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Choosing a format for built-in comments

2006-10-16 Thread Waylan Limberg

On 10/14/06, Tool69 <[EMAIL PROTECTED]> wrote:
>
> Hi Waylan,
> Thanks for pointing me this site, I've learned a lot.
> The problem is that I'm using the built-in freecomment, so if I need to
> add a field I'm obliged to change the original Django code in
> \django\contrib\comments. Is there any problem(s) with this ?
>

Only if and when you update via svn. Generally, the suggested method
is to copy the django/contrib/comments to
path/to/yourproject/comments, then edit settings.py to point to the
new location. That way, when you upgrade the django source, you won't
overwrite your changes.

-- 

Waylan Limberg
[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
-~--~~~~--~~--~--~---



Re: Django, Postgres and Server Crash

2006-10-16 Thread Mike


> What are the specs of the server? Specifically, how much RAM does it
> have and how fast are its disks? What processors are in the machine
> (for postgres, Xeons are bad, Opterons are very, very good)?

The server is rather new. 2GB of memory with a top grade Opteron (not
sure which). Once again, the server is running with low load for most
of the day, and as much as I want to, I have hard time believing its
the server that is to blame. 

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



Re: Django, Postgres and Server Crash

2006-10-16 Thread Mike

James,

Thanks for your response.

I just svn update my django directory. Doesn't the latest django
version reflect all the bug fixes? Do I have to check out
0.91-bugfixes?

Pressing 'c' on top clears everything a little bit. One thing I think I
forgot to mention is 90% of the time the server load is moderate. It is
3 times a week around early in the morning that my django and postgres
start dancing to death for me. Given that my server hardware handles
the peak time with no problem, I don't think I need to upgrade the
server.

The only out of norm activity I run is creating my data aggregate
tables 3 times a day that take load to 90% with postgres for about 5
minutes and then goes back to norm.

My guess is that somehow those aggregate builders are not cleaning up
afterwords that cause the server to start overloading and die after 5
to 6 hours. 

Thanks for your attention,
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
-~--~~~~--~~--~--~---



Re: SyncDB INT -> BIGINT

2006-10-16 Thread MindsX

So I'll  convert:
backends/ado_mssql/creation.py:
'AutoField': 'int IDENTITY (1, 1)',
'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK
([%(column)s] > 0)',

to:

'AutoField': 'bigint IDENTITY (1, 1)',
'PositiveIntegerField': 'bigint CONSTRAINT [CK_int_pos_%(column)s]
CHECK ([%(column)s] > 0)',

And see if it works...

Here goes nothing!?!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Re: Django, Postgres and Server Crash

2006-10-16 Thread James Bennett

On 10/16/06, Siah <[EMAIL PROTECTED]> wrote:
> I tried increasing the number of postgres connections, and it ended up
> completely killing the server. The server I'm working with has 2 django
> sites running, one of which receives around 3M hits a month. The other
> one somewhere around 200K hits, but I do much datawarehousing on the
> same server using Django API.

What are the specs of the server? Specifically, how much RAM does it
have and how fast are its disks? What processors are in the machine
(for postgres, Xeons are bad, Opterons are very, very good)?

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Django, Postgres and Server Crash

2006-10-16 Thread Siah

Per connection? Does it mean per request, or page view?

I tried increasing the number of postgres connections, and it ended up
completely killing the server. The server I'm working with has 2 django
sites running, one of which receives around 3M hits a month. The other
one somewhere around 200K hits, but I do much datawarehousing on the
same server using Django API.

Django really takes care of closing the connections, so do I have to
really worry about that?

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



Re: Django, Postgres and Server Crash

2006-10-16 Thread James Bennett

On 10/16/06, Siah <[EMAIL PROTECTED]> wrote:
> How many postmaster instances should be running at once?

Also, if you're running an older version of Django, be sure to update
to the "bugfixes" branch for it; the mod_python handler had a bug in
it which could leak DB connections, and which has since been fixed in
both 0.90-bugfixes and 0.91-bugfixes.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Django, Postgres and Server Crash

2006-10-16 Thread James Bennett

On 10/16/06, Siah <[EMAIL PROTECTED]> wrote:
> How many postmaster instances should be running at once?

Are you talking about 'postmaster', or 'postgres'? The default
behavior of top has a nasty habit of confusing the two; press 'c' to
have it show the full info.

That said, we have a bunch of postgres processes going at any one
time, but it doesn't bring anything down. If it's causing problems on
your database server, you may be running up against the limitations of
the hardware -- generally, you want your DB server to have the fastest
disks you can afford and lots and lots of RAM, otherwise you can get
IO-bound pretty easily and load will start spiking.


-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: django embedded web server

2006-10-16 Thread Rob Hudson

I'm also of the opinion that Django can only benefit by making the
built-in development web server better.

If I can develop Django projects without the need to install Apache (or
other web server) and use SQLite, that's awesome.  For static files I
can just use something like this:

(r'^(?P.*)$', 'django.views.static.serve',
{'document_root' : '/path/to/my/files/'})

I can do all my development self-contained in Django and have it
function as if it were hosted.  Multi-threaded would be desired in this
case.  And the barrier to setup and play with Django is much
diminished, I think.

-Rob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: mod_python help needed

2006-10-16 Thread doug

mystery solved -kinda-

the flatpages url must be LAST in the list of urls to try- not sure
why- but that fixed it.

Doug



thanks- Doug

On Oct 15, 12:15 am, "moberley" <[EMAIL PROTECTED]> wrote:
> doug wrote:
> > I am setting up mod_python on test server and having some problems. I
> > am getting 'it worked!' initially- I am able to access admin and set up
> > flatpages. But I hit a wall when just trying to do 'polls' app ...
> > getting 404s only . No problem when using development server.
>
> > test server with settings is  here->  http://oviparo.usIs there anything 
> > Django related showing up in your Apache error logs?
> 
> That's all,
> Bradley Peters


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: main menus

2006-10-16 Thread [EMAIL PROTECTED]

What seems to be giving you trouble?  It's hard to provide help if
there's not a clear question that's being asked.  It sounds like you
have a plan to create a Menu model with 7 associated TextFields.
That's maybe not necessarily how I'd go about it, but it sounds like
you're on your way to getting it done.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Migrating from Posgresql to MySql

2006-10-16 Thread [EMAIL PROTECTED]

My overall experince with PostgreSQL is that as long as the database
has a good design with all the proper datatypes, indexes etc. then it
will perform as good as, if not better than many database servers out
there (MySql included).

Do you have a sepcific query that is the problem? The guys on the
Postgres mailing lists are pretty good at diagnosing specific problems.
Are you sure your database(s) are being vacuumed and analysed properly?

For CSV import/export I usually use the built-in Python csv library.
It's pretty easy to use and database independant!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: DB caching - how does Django handle external changes to the DB

2006-10-16 Thread RajeshD

>
> My question is whether Django is a good choice for me. What I'm mostly
> worried about is if Django has some sort of a caching mechanisme that is
> hard to "turn off", making it vulnerable to not picking up changes to the
> data that is done by external processes.

Django does not have anything that's hard to turn off ;)

QuerySet instances are indeed cached. See:
http://www.djangoproject.com/documentation/db_api/#id3

The keyword here is "instance". What that means to you is that in your
views dealing with the display of externally updatable data, you should
always create and use a *new instance* of a QuerySet. This will bring
in the latest updates from your DB into Django.

The Caching Middleware is also capable of caching at various levels.
However, that's disabled by default.
(http://www.djangoproject.com/documentation/cache/)


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



Re: [django-users] suggestion

2006-10-16 Thread Marcus Mendes

Thanks so much Sirs.
I did a filter at my gmail.
Thanks again.
Marcus


On 10/15/06, Don Arbow <[EMAIL PROTECTED]> wrote:
>
> On Oct 15, 2006, at 3:18 PM, Marcus Mendes wrote:
> >
> > Hello all,
> > what about if we put "[django-users]" (or something like this) string
> > at the begining of subject of our e-mails? It will be more easy to
> > identify all e-mails tha came from  that list.
>
>
> Why clutter the subject lines with redundant information, especially
> for those with limited space to display sender, subject, and date of
> receipt?
>
> Most email programs out there can highlight or filter messages based
> on some other field in the message. All emails I receive from this
> list are routed to a folder called django-users based on the Reply-To
> header. If you're using GMail in a browser, you can filter and label
> these messages yourself.
>
> Don
>
>
>
> >
>


-- 
Marcus Mendes
"A coragem é a forma de todas as virtudes em ponto de prova" C.S.Lewis
"Onde inexiste a coragem, nenhuma outra virtude pode sobreviver, senao
por acidente" Samuel Johnson
__
linuxUser #311365
phones :  55 31 3495-6403 or 55 31 8801-3304
jabber : [EMAIL PROTECTED] // msn: [EMAIL PROTECTED]
blog: mvmendes.wordpress.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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Rob Hudson

[EMAIL PROTECTED] wrote:
> I quite often plug in a nonsense command e.g. "fudge" just to raise the
> debug page, maybe with a few

I do the same.  It would be awesome if there were a "debugger" app
(contrib app anyone?) that we could load in the template:

{{ debugger }}

That would show a unobtrusive link that when clicked would open a full
debug window like the ones on template errors with local variables,
etc.  I've seen some WSGI presentations where you can even have a
Python shell with those variables.  That sounds like it takes some work
to store those but something like this would be very useful for Django.

-Rob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



DB caching - how does Django handle external changes to the DB

2006-10-16 Thread Stefán Freyr Stefánsson
Hello.I have a deadline on a project coming up so I'm hoping that you will forgive me for posting a question that I could technically experiment with myself but because of the deadline I would very much like to receive input from the django community on whether my time is well spent on doing this or not.
So the thing is that I have an application that updates a database table. I'm currently working on this application and soon I will start working on a web frontend for displaying this data.My question is whether Django is a good choice for me. What I'm mostly worried about is if Django has some sort of a caching mechanisme that is hard to "turn off", making it vulnerable to not picking up changes to the data that is done by external processes.
What I plan on doing is create my model in Django just like I usually
do and then use Django to create the tables and everything... then I'll
modify my external application so that it pushes data into the db
structure that Django produced.

If anyone has some reading material on this or experience (s)he would like to share, I'd very much appreciate it. I'm especially looking for pitfalls that you guys might let me know of in advance to avoid because of my looming deadline.
Kind regards, Stefan Freyr.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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  -~--~~~~--~~--~--~---


Re: template error

2006-10-16 Thread doug

oh-yea!

 sudo chmod -R 755 /path-to-templates

Thanks-

Doug

On Oct 16, 10:14 am, Michael Radziej <[EMAIL PROTECTED]> wrote:
> doug schrieb:
>
>
>
> > Hey-
>
> > Why am I getting this error if the template file exists?
>
> > #
> > Template-loader postmortem
>
> > Django tried loading these templates, in this order:
>
> > * Using loader
> > django.template.loaders.filesystem.load_template_source:
> >   o /home/doug/templates/blog/entry_archive.html (File exists)
> > * Using loader
> > django.template.loaders.app_directories.load_template_source:
> >   o
> > /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/contrib/admin/templates/blog/entry_archive.html
> > (File does not exist)
> > #
>
> > I don't get the error with  './manage.py runserver'  but it throws it
> > under 'apache2-mod_python'Because the file is not readable for the web 
> > server process.
> 
> Michael


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



aggregator

2006-10-16 Thread Enquest

I'm using this script from the django website via the wiki.
http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator/bin/update_feeds.py

I'm having trouble with executing it!...

1. the "from" needs to define from where you want to grab the models.
Somehow it always fails to do this. So I'm doing something wrong. Maybe
somebody can tell me how to do it.

I execute this script by typing "python update_feed.py"
Python returns a "ImportError" that it can't find the ".models"
What do I need to do to execute it?

Enquest


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



main menus

2006-10-16 Thread Mary Adel




Dear all ;

I am developing a normal website that has a main menues and i need this main menus to be editable 
i ll develop the pages as flatfiles and i need create another model that will have 7 text boxes containing the text of the main menus
and then i can import the 7 text fields in the html of the flatpage template

Can you please help as my dead line  is tomorrow

Thank you in advance


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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  -~--~~~~--~~--~--~---





Re: print_r

2006-10-16 Thread Dirk Eschler

Am Sonntag, 15. Oktober 2006 00:01 schrieb [EMAIL PROTECTED]:
> I quite often plug in a nonsense command e.g. "fudge" just to raise the
> debug page, maybe with a few
>
> x = dir(some_var)
>
> .. to see what's in them. Once the Django debug page is up, you can
> have a really good poke around with things.
>
> The other alternative is the shell, which is great for working out what
> methods/attributes have, and tracking down the best way to use the
> DB-api etc.
>
> --Simon

How do you do that in the admin interface?

When i have a syntax error in my model, about all i get is a 404 and a note 
that the app/model wasn't found. Not very helpful to track down the source of 
the error. ;)

-- 
Dirk Eschler 
http://www.krusader.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
-~--~~~~--~~--~--~---



Setting SITE_ID dynamically

2006-10-16 Thread Afternoon

I would like to create a virtual hosting style solution which allows:

 * New sites to be created through-the-web.
 * Multiple domains to be assigned to each site.
 * Each site to have separate media and templates folders.

The requirements are not too difficult, I can implement most of this on
top of the standard sites framework without great modification. One
thing I do need to do is modify settings.SITE_ID at runtime. The domain
name is found in request.META["HTTP_HOST"] and the SITE_ID is looked-up
from that. I've created a trivially simple middleware to do this and it
works, but the settings documentation forbids runtime modification.

 * Why should settings be left unchanged? (I have some guesses)
 * Is there a way around this problem?
 * Anyone have any other suggested designs for this solution?

I can create my own version of the sites framework, which doesn't use
settings.SITE_ID, but it would be nice to reuse what's there,
especially as other parts of Django link to the framework.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: template error

2006-10-16 Thread Michael Radziej

doug schrieb:
> Hey-
> 
> 
> Why am I getting this error if the template file exists?
> 
> #
> Template-loader postmortem
> 
> Django tried loading these templates, in this order:
> 
> * Using loader
> django.template.loaders.filesystem.load_template_source:
>   o /home/doug/templates/blog/entry_archive.html (File exists)
> * Using loader
> django.template.loaders.app_directories.load_template_source:
>   o
> /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/contrib/admin/templates/blog/entry_archive.html
> (File does not exist)
> #
> 
> I don't get the error with  './manage.py runserver'  but it throws it
> under 'apache2-mod_python'

Because the file is not readable for the web server process.

Michael


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



template error

2006-10-16 Thread doug

Hey-


Why am I getting this error if the template file exists?

#
Template-loader postmortem

Django tried loading these templates, in this order:

* Using loader
django.template.loaders.filesystem.load_template_source:
  o /home/doug/templates/blog/entry_archive.html (File exists)
* Using loader
django.template.loaders.app_directories.load_template_source:
  o
/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/contrib/admin/templates/blog/entry_archive.html
(File does not exist)
#

I don't get the error with  './manage.py runserver'  but it throws it
under 'apache2-mod_python'

Thanks-

Doug


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: admin interface for legacy database

2006-10-16 Thread Ewout ter Haar

On 10/15/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:

> The value of Users.icon either has to be a valid primary key value in
> the table for the Icon model or NULL (of you have null=True in the
> ForeignKey constructor). This is because a Django ForeignKey field is a
> true foreign key in the sense that it creates a field containing the
> primary key of the foreign table *and* it creates a constraint ensuring
> that the values in that field are valid (i.e. values from the
> corresponding field in the foreign table). The constraint is significant
> here. So putting a non-existent non-NULL value in that field means it is
> no longer a foreign key.

Yes, I think that in my legacy database the relationship is not
implemented on the database level (with constraints (?)) but only
on the php, aplication level. Likewise, that "user.icon  = -1" means
"default icon for this user" is also only implemented in php, and
the default icon does not even exist in the database.

> If you want to use Django's foreign key functionality, you will need to
> make sure this field really is a foreign key (including satisfying the
> constraint). Moberly's suggestion of creating a dummy record with
> primary key value of -1 would work, for example.


So based on sugestions of both of you, I tried the following, which seems
to do what I wanted:

class Icon(models.Model):
ident = models.AutoField(primary_key=True)
filename = models.CharField(maxlength=100)

class Users(models.Model):
   ident = models.AutoField(primary_key=True)
   icon = models.ForeignKey(Icon,blank=True,db_column='icon')

   class Meta:
   db_table = 'users'

   class Admin:
   pass

   def save(self):
   try:
   print 'saving...'
   if self.icon:
   pass
   except ObjectDoesNotExist:
   print 'icon does not exists'
   self.icon = Icon(ident=-1)
super(Users, self).save() # Call the "real" save() method.


This code does what I want in the admin interface: saving a user
without choosing an icon will lead to a user with a icon field = -1
in the database, but which does not refer to any icon in the database.
Otherwise, all normal ForeignKey functionality seems to be there.

(I can choose to have an icon in my database,
with icon.ident=-1, and it will show up in the admin interface).

I am not very secure about this code, but it seems to work.
Thank you very much,

-- 
Ewout ter Haar

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

Jonathan,

I don't want to the list to be filtered to only those who have a
Rating.  I need to display ALL the products, while still showing the
average rating for those products which have a rating.

Example Table:

-- Price --- # Reviews  ---Average Rating
Product 1   $24  2  4.5
Product 2   $20  0


Sorry if my orginal post wasn't clear enough on this point.  Will your
solution still work on this basis?  Many thanks.

MerMer


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread Jonathan Buchanan

> Jonathan,
>
> Many thanks for this.
>
> Sorry to be a pain , but I have a couple of follow on questions, so I'm
> clear.
>
> 1. How should I best implement this code.  As a custom tag or in the
> view?
>
> 2. Any suggestions on how I should pass the product.id to the code?
>
> Thanks
>
> MerMer

1. The queryset we just defined will return a list of Product objects
which have a 'rating' attribute in addition to their regular
attributes. You would use this when retrieving Products in your view
or defining a queryset for use by generic views in your urls.py.

You can then access the rating with {{ product.rating }} in your templates.

2. You don't need to specify a product id - the extra select query
we've provided results in something like the following in the SQL
generated by Django's ORM:

(SELECT AVG(appname_review.rating) FROM appname_review WHERE
appname_review.product_id = appname_product.id) AS "rating"

As such, you don't have to worry about doing anything else to specify
which Product objects you want to get the average rating for - just
use your Product.objects queryset methods as normal and use
.extra(...) when you need the average rating pulled out as well - the
ORM will already be restricting the resultset to the product rows
representing the Product objects you're interested in and the
.extra(...) query above will take advantage of that.

Just shout if that's not clear enough :)

Jonathan.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Model Reuse

2006-10-16 Thread Malcolm Tredinnick

On Mon, 2006-10-16 at 02:44 -0700, Steve Wedig wrote:
> I have a thread model that I would like to reuse in multiple places.
> So a thread should have no knowledge of where it is contained.
> 
> I also have a group model and a location model. I would like to have
> multple threads in a group (1-n reln between group and thread). I
> would also like threads to appear at _multiple_ locations (so a m-n
> reln between location and thread).
> 
> I am wondering, what is the best way to accomplish this in django? I
> am reasonably familiar with the generic relation mechanism, however
> that appears to only work for 1-n relationships. Plus I don't want to
> a thread to worry about where/how it is used/contained.

A many-to-many relation is identical to two one-to-many relations put
back-to-back. Think about how a many-to-many relation is implemented at
the table level (whether by Django or in any database setup): you have a
table in the middle that contains pairs of entries, one from each end of
the many-to-many relation.

So I would think you could create a many-to-many generic relation by
having an intermediate model that is 1-n to both the thread and location
models. All the intermediate model does is handle the connection. Note
that I haven't actually worked out the details, but I can't think of any
insurmountable problem. If you get stuck implementing this, sing out and
we should be able to help.

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



Re: Migrating from Posgresql to MySql

2006-10-16 Thread Rory Campbell-Lange

Hi Giovanni

Postgresql has a very useful COPY command which should be able to do what you
need.

See
http://www.postgresql.org/docs/8.1/static/sql-copy.html

You will see that you can export to files in various custom formats, while CSV
mode is supported specially.

You may need to issue the copy command as \copy unless you are running as the
Postgres superuser.

As a matter of interest, what parameters have you tuned in Postgresql? Have you
looked at the output of EXPLAIN ANALYZE? Have you posted to the Postgres lists?

Regards
Rory

COPY tablename [ ( column [, ...] ) ]
FROM { 'filename' | STDIN }
[ [ WITH ] 
  [ BINARY ]
  [ OIDS ]
  [ DELIMITER [ AS ] 'delimiter' ]
  [ NULL [ AS ] 'null string' ]
  [ CSV [ HEADER ]
[ QUOTE [ AS ] 'quote' ] 
[ ESCAPE [ AS ] 'escape' ]
[ FORCE NOT NULL column [, ...] ]


On 16/10/06, Giovanni Giorgi ([EMAIL PROTECTED]) wrote:
> 
> Hi all,
>  I have loved django for its readiness with PostgreSQL.
> I have done the set up of my blog on openhosting.com.
> But when I tried to set up more complex applications, I noted
> postgresql is very slow on my virtual linux machine.
> I have tried to tune it in a bunch of ways without so much success: the
> applications I am developing are quite small and slow to work.
> 
> MySQL is faster but I am not so sure I want to leave the postgres guy
> for a db with so less feature.
> There is some tools to migrate postgresql data to mysql (for testing
> purpose)?
> I have not found a decent tool to do that (I have string records with
> CRs aka "\n").
> PostgreSQL cannot export in Comma Separated Value (CSV) and SQL
> export-import has some minor convention problems.
> What is your experience?
> Any hint?
> 
> 
> > 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Displaying number of visitors

2006-10-16 Thread orestis

OK, I did it. Unfortunately, the session table is using pickled data,
so the processing has to be done in django. Here it goes:

In views that you would like to refresh the active state of a user,
add:

request.session['last_seen']= datetime.datetime.now()

Then, in a util.py :

from django.contrib.sessions.models import Session
from django.contrib.auth.models import User

import datetime

time_limit = datetime.timedelta(minutes=10)

def get_active():
sessions = Session.objects.all()
active = []
now = datetime.datetime.now()
for s in sessions:
s_dict = s.get_decoded()
if 'last_seen' in s_dict:
last_seen = s_dict['last_seen']
if now - last_seen < time_limit:
user = User.objects.get(pk=s_dict['_auth_user_id'])
active.append(user)
return active

Then, just create a template tag that prints out the users.
Maybe this should be moved in the docs/wiki ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread Jonathan Buchanan

On 10/15/06, MerMer <[EMAIL PROTECTED]> wrote:
>
> I have two Models.
>
> 1.  Product
> 2.  Review -  There can be many reviews for any product (one -to many
> relationship)
>
> One of the fields of Review is "Rating". This  holds an integer between
> 1 and 5.
>
> I want to display a list of Products, and display the average review
> rating for each product.
>
> I can see how I can easily display the number of reviews for each
> product by using
> "review_set.count"  but it's not clear to me how I go about displaying
> the average rating.
>
> Could anybody set me on the right path on this?  I'm sure it must be a
> common type of requirement.  I'm very new to both Python and Django.
>
> MerMer

The following should give each Product a "rating" attribute containing
the average rating - you'll need to change the table names to match
whatever you have, and you can omit the NOT NULL condition if ratings
are mandatory for your review table.

Product.objects.all().extra(
select={
'rating': 'SELECT AVG(appname_review.rating) FROM
appname_review WHERE appname_review.product_id = appname_product.id
AND appname_review.rating IS NOT NULL',
}
)

The AVG function may be database dependent - I ran this on sqlite to test it.

Jonathan.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Re: ImageField

2006-10-16 Thread Guillermo Fernandez Castellanos

I had a similar problem. I havent found any definitive solution, but
there is some solutions that might help:
Create a new model:

class Image(models):
image = models.ImageField(...)

Add to your post model:
images = models.ForeignKey(Image)

Then, create a special view to create posts, where all the images of
the post are displayed with their full path. Something like:
Images:
http://www.yoursite.com/post/2006/10/24/image1.gif
http://www.yoursite.com/post/2006/10/24/image2.gif
http://www.yoursite.com/post/2006/10/24/image3.gif
Add Image

The idea is, when a person is writting a post and they wish to add an
image, they simply have to copy-paste the field above.

Same for files.

Not the best solution, but the best I've found. Better ideas welcomed.

Hope it helps.

G

On 10/16/06, Ramdas S <[EMAIL PROTECTED]> wrote:
> Hi,
>
> In a classic blog/content driven web app, if you need to add more than 2
> images in an article body, what you should do?
>
> I know I can manage by  creating multiple ImageFields in my model, to
> accomodate more pictures. but is there any other solutions?
>
> Suppose I need to publish  some stuff that may have 10 pics inside, what
> needs to be done? Creating 10 models. image.field (blank=True) inside a
> model looks ugly.
>
> Any other ideas?
>
> Thanks
>
> Ramdas
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Model Reuse

2006-10-16 Thread Steve Wedig

I have a thread model that I would like to reuse in multiple places.
So a thread should have no knowledge of where it is contained.

I also have a group model and a location model. I would like to have
multple threads in a group (1-n reln between group and thread). I
would also like threads to appear at _multiple_ locations (so a m-n
reln between location and thread).

I am wondering, what is the best way to accomplish this in django? I
am reasonably familiar with the generic relation mechanism, however
that appears to only work for 1-n relationships. Plus I don't want to
a thread to worry about where/how it is used/contained.

Thanks!
- Steve

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Migrating from Posgresql to MySql

2006-10-16 Thread Giovanni Giorgi

Hi all,
 I have loved django for its readiness with PostgreSQL.
I have done the set up of my blog on openhosting.com.
But when I tried to set up more complex applications, I noted
postgresql is very slow on my virtual linux machine.
I have tried to tune it in a bunch of ways without so much success: the
applications I am developing are quite small and slow to work.

MySQL is faster but I am not so sure I want to leave the postgres guy
for a db with so less feature.
There is some tools to migrate postgresql data to mysql (for testing
purpose)?
I have not found a decent tool to do that (I have string records with
CRs aka "\n").
PostgreSQL cannot export in Comma Separated Value (CSV) and SQL
export-import has some minor convention problems.
What is your experience?
Any hint?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



ImageField

2006-10-16 Thread Ramdas S
Hi,
 
In a classic blog/content driven web app, if you need to add more than 2 images in an article body, what you should do?
 
I know I can manage by  creating multiple ImageFields in my model, to accomodate more pictures. but is there any other solutions?
 
Suppose I need to publish  some stuff that may have 10 pics inside, what needs to be done? Creating 10 models. image.field (blank=True) inside a model looks ugly.
 
Any other ideas?
 
Thanks
 
Ramdas 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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  -~--~~~~--~~--~--~---


limit_choices_to according the field of the current model?

2006-10-16 Thread Aidas Bendoraitis

Hello Djangoers!

I have many Vocabularies and nested Categories in each of the
Vocabularies, described in the following way:


from django.db import models

class Vocabulary(models.Model):
name = models.CharField(maxlength=20)

class Category(models.Model):
vocabulary = models.ForeignKey(Vocabulary)
name = models.CharField(maxlength=20)
parent = models.ForeignKey('self', null=True, related_name='child_set')


Is it possible to limit choices of the parent categories according the
chosen vocabulary? If the category is saved (so the vocabulary_id is
known to the system), I'd like that the administrator would see only
the parent categories of the chosen vocabulary in the select list.

Regards,
Aidas Bendoraitis [aka Archatas]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---