How do I model optional Parent/Child relationships, e.g. not all Tasks are related to a Project?

2009-03-06 Thread Doug

I have 2 related models, Project and Task.

What's the best way to set up my models so a Task can either be part
of a Project or not? Do I set up a "dummy" Project for Tasks which
aren't related to a specific Project? Or is there a way to set "Null"
on the FK of a Task for the Project field?

Here are my models: http://dpaste.com/8321/

Many 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Can I set user=request.user automatically when using create_object Generic View?

2009-03-08 Thread Doug

I am writing a simple task management app in Django. I am trying to
use the "create_object" generic view to allow a logged on user to
create a new Task. It does work, but the form displays a drop-down for
the Task's "user" field allowing the user to pick any user as the
task's owner. This is bad. I have solved that by setting
"editable=False" on my Task model.

How do I  automatically set the Task's "user" field to the logged on
user before saving the new Task? Can I use the create_object Generic
View or do I need to write a custom view?


Here's the specific section of the Django docs which is throwing me:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/?from=olddocs#using-a-subset-of-fields-on-the-form

===
"If you specify fields or exclude when creating a form with ModelForm,
then the fields that are not in the resulting form will not be set by
the form's save() method. Django will prevent any attempt to save an
incomplete model, so if the model does not allow the missing fields to
be empty, and does not provide a default value for the missing fields,
any attempt to save() a ModelForm with missing fields will fail. To
avoid this failure, you must instantiate your model with initial
values for the missing, but required fields, or use save(commit=False)
and manually set any extra required fields:

instance = Instance(required_field='value')
form = InstanceForm(request.POST, instance=instance)
new_instance = form.save()

instance = form.save(commit=False)
instance.required_field = 'new value'
new_instance = instance.save()
"
=

The Task model is as follows:

# models.py
class Task(models.Model):

user = models.ForeignKey(User, editable=False)
name = models.CharField(max_length=100)
due = models.DateTimeField(blank=True, null=True)

# urls.py
task_dict = {'model': Task, 'login_required': True}

urlpatterns = patterns('',
url(r'^create/$', create_object, task_dict)


Many 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



limiting the scope of a ForeignKey relation to within a model?

2009-09-20 Thread Doug

Lets say for instance that I have the following model, Project, which
is related to an Image model in the following ways:


class Project(models.Model):
...
images = models.ManyToManyField(Image, related_name='image')
lead_image = models.ForeignKey(Image, related_name='lead_image')
   


Is there any way to set up this relationship so that the lead_image
choices are limited to only those in the "images" manytomany
association of the current instance of Project?

Thanks for any advice you have.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help customizing the admin functionality

2009-09-21 Thread Doug

Gustavo,

You should take a look at these projects:

django-massmedia

http://opensource.washingtontimes.com/projects/django-massmedia/
https://code.launchpad.net/~vcs-imports/django-massmedia/trunk

django-filebrowser

http://code.google.com/p/django-filebrowser/

Photologue

http://code.google.com/p/django-photologue/

Good luck!

Doug





On Sep 21, 7:58 am, gustavo  wrote:
> Hello friends!
>
> I am changing from php to python.
> I am building a website to a photographer and I would like to build
> the following functionality: I would like to upload a zip file and
> build a method to explode the photos and build a library.
>
> I have already created a project and an app with two model classes,
> galery and photo.
>
> Does anyone would help me with that?
>
> Thanks.
>
> Gustavo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Oracle connection "cx_Oracle.DatabaseError: ORA-00911: invalid character"

2009-05-17 Thread Doug

When I attempt to use Oracle as the backend for Django, I get this
error on issuing the 'syndb' command:
"cx_Oracle.DatabaseError: ORA-00911: invalid character".

** Configuration:  Python 2.5; cx_Oracle 5.0.1- 10g

** Setting:  Backend=oracle; User=django; PW=django; Host=BLANK;
Port=BLANK

**  Complete Error Stack:

Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "C:\Python25\lib\site-packages\django\core\management.py", line
1672, in
execute_manager
execute_from_command_line(action_mapping, argv)
  File "C:\Python25\lib\site-packages\django\core\management.py", line
1571, in
execute_from_command_line
action_mapping[action](int(options.verbosity),
options.interactive)
  File "C:\Python25\lib\site-packages\django\core\management.py", line
534, in s
yncdb
cursor.execute(statement)
  File "C:\Python25\lib\site-packages\django\db\backends\oracle
\base.py", line 7
2, in execute
return Database.Cursor.execute(self, query, params)
cx_Oracle.DatabaseError: ORA-00911: invalid character


**  I can connect outside of Django:
>>> USER = 'django'; DATABASE_PW = 'django'; DATABASE_NAME = 'XE';
>>> conn_str = "%s/%...@%s" % (USER, DATABASE_PW, DATABASE_NAME)
>>> conn_str
'django/dja...@xe'
>>> myDB = cx_Oracle.connect(conn_str)
>>> myDB


Can someone help me with some guidance?  What am I doing wrong?

Regards,
Doug
www.rmsfinance.com

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



Re: Oracle connection "cx_Oracle.DatabaseError: ORA-00911: invalid character"

2009-05-18 Thread Doug

Thanks for your response Karen.  And I am so new into Django that
there is no real harm is re-installing v1, and trying again.  However,
I believe that I am experiencing the problem with V1.  I'll let you
know what I find.

Doug

On May 17, 4:58 pm, Karen Tracey  wrote:
> On Sun, May 17, 2009 at 3:14 PM, Doug  wrote:
>
> > When I attempt to use Oracle as the backend for Django, I get this
> > error on issuing the 'syndb' command:
> > "cx_Oracle.DatabaseError: ORA-00911: invalid character".
>
> > ** Configuration:  Python 2.5; cx_Oracle 5.0.1- 10g
>
> and Django version...?
>
>
>
>
>
>
>
> > ** Setting:  Backend=oracle; User=django; PW=django; Host=BLANK;
> > Port=BLANK
>
> > **  Complete Error Stack:
>
> > Traceback (most recent call last):
> >  File "manage.py", line 11, in 
> >    execute_manager(settings)
> >  File "C:\Python25\lib\site-packages\django\core\management.py", line
> > 1672, in
> > execute_manager
> >    execute_from_command_line(action_mapping, argv)
> >  File "C:\Python25\lib\site-packages\django\core\management.py", line
> > 1571, in
> > execute_from_command_line
> >    action_mapping[action](int(options.verbosity),
> > options.interactive)
> >  File "C:\Python25\lib\site-packages\django\core\management.py", line
> > 534, in s
> > yncdb
> >    cursor.execute(statement)
>
> File "C:\Python25\lib\site-packages\django\db\backends\oracle
>
>
>
>
>
> > \base.py", line 7
> > 2, in execute
> >    return Database.Cursor.execute(self, query, params)
> > cx_Oracle.DatabaseError: ORA-00911: invalid character
>
> > **  I can connect outside of Django:
> > >>> USER = 'django'; DATABASE_PW = 'django'; DATABASE_NAME = 'XE';
> > >>> conn_str = "%s/%...@%s" % (USER, DATABASE_PW, DATABASE_NAME)
> > >>> conn_str
> > 'django/dja...@xe'
> > >>> myDB = cx_Oracle.connect(conn_str)
> > >>> myDB
> > 
>
> > Can someone help me with some guidance?  What am I doing wrong?
>
> The file django\core\management.py, referenced several times in that
> traceback, doesn't exist in Django 1.0.  It existed in Django 0.96 but was
> refactored into a directory django\core\management before the 1.0 release.
> So you seem to be running some version of Django lower than 1.0.  Yet 1.0
> was the first version to have working Oracle support -- the branch that got
> Oracle working wasn't merged back to trunk until after 0.96 was released.
>
> So, if you are running a 0.96.x version of Django I wouldn't expect the
> Oracle backend to work there.  If you are running an SVN checkout from after
> the Oracle branch merge (r5519), I have no idea what's going wrong.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Possible to create models programatically?

2010-07-20 Thread Doug
I have a similar issue, with a bunch of very similar apps that I need
in separate tables that all have the same base structure.  I keep the
common models in a file called models_base.py and then use execfile in
the models.py file for each app.  It's basically like a php or c
include in that in 'inserts' in the local.  You can also make changes/
add fields to a model after it's defined by placing the assignments
after the execfile.

execfile('somefilenameandpath.py',locals(),globals())

Having said that, I don't think it is generally a good idea to do
this.  It seems much better now to use subclassing with tables
specified, or some other approach.  In my case, the project was built
well before model subclassing was implemented.  Otherwise we woud have
used that.  It does work though if you have to do it that way.


On Jul 20, 7:56 pm, Andy  wrote:
> I have N models that are identical except the model names (i.e. they
> all have the same attributes, methods):
>
> MyModel0, MyModel1, MyModel2, ...
>
> Normally I'd need to type out the model definitions for those N models
> by hand inside models.py.
>
> Is there a way to generate the N model definitions programatically
> instead of manually?

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



Re: Synching samba users to django users?

2010-09-21 Thread Doug
You could create a secondary python script running as root that polls
a queue or config file generated by your django app.  Have that script
perform the requested actions by running the same executables as a sub
process and checking the exit codes.  If you need immediate responses,
it could run like a daemon/service sleeping between poll intervals...
or via a cron job if you can deal with the delayed actions.

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



Re: dictionary doesn't get properly updated

2010-10-07 Thread Doug
Could it be that garbage collection is deleting your "tm" instance
when it falls out of scope at the end of the view call?  If that is
the only place you've instantiated it, I'm guessing the reference
count would go to zero 'singleton' or not.

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



Re: trying to get a cache per request

2010-10-09 Thread Doug
Why not just stick it on the request object?

def myview(request):
request.mycache=MyCacheClass()

then it's available everywhere the request object is.  If you are
wanting something that can be used in a template tag without
explicitly passing the request object (or your cache object) in, you
probably want thread locals and a middleware to reset after each
time.  I've had to do this a couple of times, and regretted in in all
but one (a template loader - we serve many sites from one fastcgi
instance and that was the only way I could think to map templates for
different sites).

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



Re: trying to get a cache per request

2010-10-09 Thread Doug
Look around for python docs on threading.local, which lets you set a
'global' variable for just that thread.  Since a request is only going
to happen in a single thread, that lets you have a per-request global
that can be used for cache storage.  With middleware to set the
threading local instance up, and remove it at the end of the request.
I think it will do what you want.  One bit of weirdness I noticed was
that you always need to import the global in exactly the same way
everywhere you want it, otherwise you may not be referring to the same
variable.

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



Re: my first (public) app: django-requires_js_css

2010-10-24 Thread Doug
I'm also interested in something like this.  I've tried it a couple of
different ways, but have not been all the happy with the results/
implementation.  It seemed like post-parsing for tokens was trouble
since it hurt performance somewhat, and gets ugly if you are serving
the occasional big file or using a generator for output.  I also tried
tracking via a threadlocals global and letting my 'content' render
once to get it updated and then feeding that into another render with
the barebones html/head/body sections.  That last one has been working
for a couple of years, but the shame keeps me up at night sometimes.

What I would really love is a way to extend the template parser to
allow for a rendering order per-block, so that some portions of the
template (ie head includes in this case) can be deferred until the
last pass and examine the context for various media 'requests' made by
tags (or other related logic).  I had also thought that preprocessing
the nodelists into order queues could allow for a kind of automatic
generator to be made so that multiple nodelists of the same order
could be yielded to the response to stream the output (though doing
that would prevent the automatic css/js stuff).  I don't know if any
of this is even reasonably possible with the current template system,
but I'd sure love if it was.

An easy but ugly approach might be a template tag that 'wraps' the
entire template:


{% delayedrender %}

 {% defer %}This stuff gets rendered last{% enddefer %}


This stuff gets rendered first

{ % enddelayedrender %}


Unfortunately I haven't had enough time to explore either option any
further.

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



Re: I have an idea for a new tag

2010-11-19 Thread Doug
An easy alternative is to make a sort filter:

register.filter('sort',lambda x: sorted(x))

and then do

{% for k,v in mydict.items|sort %}
   {{k}}:{{v}}
{% endfor %}

I had to look at the docs to realize there isn't a sort filter in
django for some reason.  I long ago added the one above to builtins
and I don't know how I could have lived without it.

Another handy one I feel the same way about is "contains"

register.filter('contains', lambda x,y: y in x or [])

{% if mydict|contains:"foo" %}
This is foo: {{mydict.foo}}
{% endif %}

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



Re: my models are remembering old fields that I have since deleted

2011-05-10 Thread Doug

Got it. I was assuming that snycdb was dropping the old tables for me.
All of the crazy stuff that was happening seems to be explained.
Thanks.

On 5/7/2011 9:50 PM, George Silva wrote:

Just drop the old tables and run syncdb again!

Cheers

On Sat, May 7, 2011 at 10:45 PM, Nick Arnett > wrote:




On Sat, May 7, 2011 at 6:05 PM, Dug_the_Math_Guy
mailto:dugthemath...@gmail.com>> wrote:

HI I'm new to Django and just getting some models going. I started
with a more complex model and got errors so I scaled back to a
more
minimalist model to see if I could get that working. I flushed my
database to get rid of any old info and synched the DB to
create the
new more minimal models. 



Syncing the database doesn't delete anything, ever.  Probably the
simplest way to deal with this is to rename (in the database) the
tables that you have changed, then run syncdb to create your new
tables, then copy the old data into the new tables and delete the
old tables.

If by "flushed" you mean you deleted the old tables (or the whole
database), then something else is going on.

Nick
-- 
You received this message because you are subscribed to the Google

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




--
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


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



Best practices for 1.5 configurable user model and profiles

2013-02-22 Thread Doug
I am curious how people are handling the new 1.5 user model with regard to 
User Profiles. Is it best to add all profile information to a custom user 
model? Or keep the user model for authentication information only and 
create a one-to-on or foreign key to a profile model (similar to the 
pre-1.5 best practice)?

In my case, users will have an avatar, a bio, a location, and other profile 
type information.

What are the pros and cons of each approach?

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




Re: Best practices for 1.5 configurable user model and profiles

2013-02-27 Thread Doug
Russ,

Thanks so much for your reply. I guess the confusion is around the 
subjectivity of what is considered "identifying the user". In my case, the 
additional data is not application related, it is project related and would 
be part of a "Profile" that is used throughout the site across many 
applications. 

I guess the more specific question would be: should user data be limited to 
data necessary for _authentication_. This makes sense when you take into 
account that the app it is a part of is "auth". 
So when you say "core identifying information", do you mean authentication 
information? In this case, avatar would not fit the description, in much 
the same way that bio or location would not. 

Perhaps I am overcomplicating things, but I want to create a solution that 
is as simple as possible without limiting flexibility. 

I guess what would help is an idea of what the primary reason was for the 
change to the user model in 1.5. Was it primarily to address the issue of 
an easier way to provide alternative authentication (versus writing a 
separate backend)? Or was it also to make it easier to create the concept 
of a "profile"?

On Saturday, February 23, 2013 11:15:20 PM UTC-5, Russell Keith-Magee wrote:
>
> Hi Doug,
>
> Obviously, it's still early days, so "best practice" hasn't really evolved 
> yet. However, based on what I've done with custom user models so far, my 
> advice would be to only put on the User model those things that are part of 
> identifying the User, and maintain a profile for any application-related 
> information that is user specific.
>
> So - things like a username, primary contact email address, and an avatar 
> would be reasonable things to have on the User model.
>
> Phone number *might* be appropriate for the User model -- depending on 
> whether a phone number is something that is core identifying information 
> for users of you project, or just additional profile information.
>
> Things like a biography or current location aren't key concepts for a user 
> -- they're something that can be isolated as part of a profile that is 
> contained in one or many separate user-related applications. 
>
> In many respects, this is exactly the same story that Django has always 
> maintained -- the difference is that now you have more control over exactly 
> what is considered "core" identifying information.
>
> Of course, there are exceptions to every rule -- and the one exception 
> that exists here is performance based. Using profile objects requires the 
> use of a join, and if you're doing a *lot* of profile joins, you might find 
> that denormalizing that join, and putting profile information on the base 
> user object may be worthwhile. 
>
> However, this should be considered a potential performance enhancement, 
> not architectural advice -- IMHO, most users won't be dealing with enough 
> query volume to be affected by this problem, and should be using profile 
> objects rather than denormalizing.
>
> Yours,
> Russ Magee %-)
>
> On Fri, Feb 22, 2013 at 11:10 PM, Doug >wrote:
>
>> I am curious how people are handling the new 1.5 user model with regard 
>> to User Profiles. Is it best to add all profile information to a custom 
>> user model? Or keep the user model for authentication information only and 
>> create a one-to-on or foreign key to a profile model (similar to the 
>> pre-1.5 best practice)?
>>
>> In my case, users will have an avatar, a bio, a location, and other 
>> profile type information.
>>
>> What are the pros and cons of each approach?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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




Re: Best practices for 1.5 configurable user model and profiles

2013-02-27 Thread Doug
Thanks Shawn. So what is your take? Only authentication data in User? 
Separate Profile model and app? 

On Wednesday, February 27, 2013 12:07:55 PM UTC-5, Shawn Milochik wrote:
>
> Do a search on the history of the django-developers mailing list. 
> There are many reasons, and they were discussed for literally years. 
>
> Some of the main ones that come to mind: 
>
> first_name/last_name is US-centric. 
> e-mail address field length was too short. 
> e-mail address could not be used as the username 
>

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




Re: Problem with translations

2013-09-05 Thread Doug
I've found some other people with the same 
issue. 
 Looking at the 
source,
 
the issue is directly related to IOError, so your assumption sounds 
correct, django can not access nor read the files.  I don't believe this is 
a django specific issue but server config issue.

I hope this helps.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Problem with translations

2013-09-05 Thread Doug
Follow-up: just for good measure could you tell me what you have in your 
settings for `LANGUAGE_CODE` and what languages you are trying to support? 
 If by some small chance you are trying to support a language not apart of this 
set , an 
issue could occur with threading.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Error related to googlebot?

2014-01-24 Thread Doug
I am having this same exact problem. Did you ever find a resolution? 

Thanks.
Doug

On Monday, July 12, 2010 2:10:49 PM UTC-4, Tor Nordam wrote:
>
> I'm currently writing a blog framework in django, and I have it up an 
> running (on www.presskanne.com). During the last 20 hours or so, I 
> have gotten about 60 emails with error 500 messages. They seem to 
> originate from different pages all over the site, but they all have 
> two things in common: 
>
> The tracebacks all show that the problem is in importing one 
> particular model 
>
> The clients are all either googlebot or yahoo slurp 
>
> Also, I can't reproduce any of the errors myself. When I visit the 
> offending urls, everything either seems fine, or in the case of a 
> nonexistent page, I get a nice 404 message. 
>
> So my question is if there is anything in particular which might cause 
> the page to crash when a searchbot tries to load it, but not do the 
> same for a regular user.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/08289acf-2fef-4953-b77c-153001ec8ef9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Error related to googlebot?

2014-01-25 Thread Doug
Thanks for the response.

I'm not doing any user agent sniffing, and I don't have a robots.txt. 

On Monday, July 12, 2010 2:10:49 PM UTC-4, Tor Nordam wrote:
>
> I'm currently writing a blog framework in django, and I have it up an 
> running (on www.presskanne.com). During the last 20 hours or so, I 
> have gotten about 60 emails with error 500 messages. They seem to 
> originate from different pages all over the site, but they all have 
> two things in common: 
>
> The tracebacks all show that the problem is in importing one 
> particular model 
>
> The clients are all either googlebot or yahoo slurp 
>
> Also, I can't reproduce any of the errors myself. When I visit the 
> offending urls, everything either seems fine, or in the case of a 
> nonexistent page, I get a nice 404 message. 
>
> So my question is if there is anything in particular which might cause 
> the page to crash when a searchbot tries to load it, but not do the 
> same for a regular user.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64d48d9c-7359-4996-ae51-1a6655fe6d4a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Error related to googlebot?

2014-01-25 Thread Doug
Here's an example stack trace:

Traceback (most recent call last):

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/core/handlers/base.py", line 103, in get_response
resolver_match = resolver.resolve(request.path_info)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/core/urlresolvers.py", line 319, in resolve
for pattern in self.url_patterns:

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)

  File "/home/possiblecity/possiblecity/production/
possiblecity/possiblecity/urls.py", line 11, in 
autocomplete_light.autodiscover()

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/autocomplete_light/registry.py", line 237, in autodiscover
_autodiscover(registry)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/autocomplete_light/registry.py", line 190, in _autodiscover
import_module('%s.autocomplete_light_registry' % app)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)

  File "/home/possiblecity/possiblecity/production/
possiblecity/possiblecity/apps/lotxlot/autocomplete_light_registry.py", 
line 4, in 
from .models import Lot

  File "/home/possiblecity/possiblecity/production/
possiblecity/possiblecity/apps/lotxlot/models.py", line 17, in 
from apps.comments.models import Comment

  File "/home/possiblecity/possiblecity/production/
possiblecity/possiblecity/apps/comments/models.py", line 10, in 
from actstream.models import followers

  File "/home/possiblecity/lib/python2.7/actstream/models.py", line 22, in 

User = get_user_model()

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/contrib/auth/__init__.py", line 127, in 
get_user_model
user_model = get_model(app_label, model_name)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/db/models/loading.py", line 230, in get_model
self._populate()

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)

  File "/home/possiblecity/.virtualenvs/prod/lib/python2.
7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)

  File "/home/possiblecity/possiblecity/production/
possiblecity/possiblecity/apps/core/models.py", line 4, in 
from actstream.models import Follow

ImportError: cannot import name Follow


,
POST:,
COOKIES:{},
META:{'HTTP_ACCEPT': '*/*',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
 'HTTP_CONNECTION': 'close',
 'HTTP_FORWARDED_REQUEST_URI': '/lots/4778/',
 'HTTP_FROM': 'googlebot(at)googlebot.com',
 'HTTP_HOST': 'possiblecity.co',
 'HTTP_HTTPS': 'off',
 'HTTP_HTTP_X_FORWARDED_PROTO': 'http',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; Googlebot/2.1; +
http://www.google.com/bot.html)',
 'HTTP_X_FORWARDED_FOR': '66.249.73.20',
 'HTTP_X_FORWARDED_HOST': 'possiblecity.co',
 'HTTP_X_FORWARDED_PROTO': 'http',
 'HTTP_X_FORWARDED_SERVER': 'possiblecity.co',
 'HTTP_X_FORWARDED_SSL': 'off',
 'PATH_INFO': u'/lots/4778/',
 'QUERY_STRING': '',
 'RAW_URI': '/lots/4778/',
 'REMOTE_ADDR': '66.249.73.20',
 'REMOTE_PORT': '80',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': 'possiblecity.co',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'gunicorn/17.5',
 'gunicorn.socket': ,
 'wsgi.errors': ', mode 'w' at 0x7f0d45ef51e0>,
 'wsgi.file_wrapper': ,
 'wsgi.input': ,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>

On Monday, July 12, 2010 2:10:49 PM UTC-4, Tor Nordam wrote:
>
> I'm currently writing a blog framework in django, and I have it up an 
> running (on www.presskanne.com). During the last 20 hours or so, I 
> have gotten about 60 emails with error 500 messages. They seem to 
> originate from different pages all over the site, but they all have 
> two things in common: 
>
> The tracebacks all show that the problem is in importing one 
> particular model 
>
> The clients are all either googlebot or yahoo slurp 
>
> Also, I can't reproduce any of the errors myself. When I visit the 
> offending urls, everything eith

Re: Error related to googlebot?

2014-01-25 Thread Doug
Also, if I spoof the user agent (using a chrome plugin), I don't get the 
error.

On Monday, July 12, 2010 2:10:49 PM UTC-4, Tor Nordam wrote:
>
> I'm currently writing a blog framework in django, and I have it up an 
> running (on www.presskanne.com). During the last 20 hours or so, I 
> have gotten about 60 emails with error 500 messages. They seem to 
> originate from different pages all over the site, but they all have 
> two things in common: 
>
> The tracebacks all show that the problem is in importing one 
> particular model 
>
> The clients are all either googlebot or yahoo slurp 
>
> Also, I can't reproduce any of the errors myself. When I visit the 
> offending urls, everything either seems fine, or in the case of a 
> nonexistent page, I get a nice 404 message. 
>
> So my question is if there is anything in particular which might cause 
> the page to crash when a searchbot tries to load it, but not do the 
> same for a regular user.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/015cb444-148d-46de-b998-d9d67f1811fd%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Turn off migrations completely in Django 1.7

2015-11-20 Thread doug

On 2015-11-20 16:37, Frank Malina wrote:

RE: Carl Meyer

To my knowledge, out of the many hundreds of
thousands of Django users, you are the first and only one to

request a

way to turn off migrations entirely.


No he isn't, Django migrations are ridiculous waste of time, never
work and make me angry.
I work with Django from v0.96 and it never got in the way as much as
it does now.

 --
 You received this message because you are subscribed to the Google
Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users [1].
 To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b1a2ff2b-7888-4a52-aaa8-c09a9b036838%40googlegroups.com
[2].
 For more options, visit https://groups.google.com/d/optout [3].


Links:
--
[1] http://groups.google.com/group/django-users
[2]
https://groups.google.com/d/msgid/django-users/b1a2ff2b-7888-4a52-aaa8-c09a9b036838%40googlegroups.com?utm_medium=email&utm_source=footer
[3] https://groups.google.com/d/optout


Please forgive this simple question .

How can I change the email address associated with this group ?

I want to keep getting the emails but to a different address.

Thanks

doug

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/486d3e2e4179fbd43336f900899b7e9b%40gearscape.net.
For more options, visit https://groups.google.com/d/optout.


alternative to model inheritance?

2007-09-03 Thread Doug

I m creating new models for a portfolio application. I am creating a
Project class and one of the fieldsof this class will be "type". There
will be four types of Projects: Student, Professional, Competition,
Personal. Each of these types will share most fields but some types
will have addtional fields. At first I thought something like this
would be best...

class Project(models.Model):
name = models.CharField(max_length=250)
slug = models.SlugField(prepopulate_from=('name',))
date = models.DateField()
description = models.TextField(blank=True)
disciplines = models.ManyToManyField(Discipline)
type = models.ForeignKey(Type)
publish = models.BooleanField("Publish?", default=False)
images = models.ManytoManyField(imageBank.Image)
lead_image = models.ForiegnKey(imageBank.Image)

class StudentProject(Project)
critic = models.CharField(max_length=250)

class ProfessionalProject(Project)
   client = models.ForeignKey(Client)

etc, etc...


However, after looking through some of the posts on this site, it
appears that this will not work yet in Django. As a new user of Django
and Python, I was hoping to get some advice on what the alternative
methods of handling this situation are.

Thanks for your help.

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?hl=en
-~--~~~~--~~--~--~---



Re: alternative to model inheritance?

2007-09-03 Thread Doug

I guess my issue is that I only want to have to enter the project
once. I don't want to create a Project and then have to create a
StudentProject and link them via a foreign key. I'm having trouble
visualizing how this would look/work in the admin. Ideally, I would
have a select box that asked for the project type (student,
professional, ect) and depending on which I chose, the appropriate
extra fields would appear. I realize that his is not possible with a
standard Django install, so I am trying to figure out the best
alternative.

On Sep 3, 11:27 am, Stefan Rimaila <[EMAIL PROTECTED]> wrote:
> I don't think you need to create this kind of
> inheritance, but instead, you could create projects with ForeignKeys that
> point to a certain project type.
>
> This would of course then require some additional tweaking or customising
> on your models (such as the client, discipline, etc.), as Django, IIRC,
> isn't yet capable of doing what you've described below.
>
> --
> Stefan Rimaila
> "A few bolts loose and a set of switches broken"
> Blog, personal portfolio & fun stuff:http://www.studionyami.com
>
> On Mon, 3 Sep 2007, Doug wrote:
>
> > I m creating new models for a portfolio application. I am creating a
> > Project class and one of the fieldsof this class will be "type". There
> > will be four types of Projects: Student, Professional, Competition,
> > Personal. Each of these types will share most fields but some types
> > will have addtional fields. At first I thought something like this
> > would be best...
>
> > class Project(models.Model):
> > name = models.CharField(max_length=250)
> > slug = models.SlugField(prepopulate_from=('name',))
> > date = models.DateField()
> > description = models.TextField(blank=True)
> > disciplines = models.ManyToManyField(Discipline)
> > type = models.ForeignKey(Type)
> > publish = models.BooleanField("Publish?", default=False)
> > images = models.ManytoManyField(imageBank.Image)
> > lead_image = models.ForiegnKey(imageBank.Image)
>
> > class StudentProject(Project)
> > critic = models.CharField(max_length=250)
>
> > class ProfessionalProject(Project)
> >client = models.ForeignKey(Client)
>
> > etc, etc...
>
> > However, after looking through some of the posts on this site, it
> > appears that this will not work yet in Django. As a new user of Django
> > and Python, I was hoping to get some advice on what the alternative
> > methods of handling this situation are.
>
> > Thanks for your help.
>
> > 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?hl=en
-~--~~~~--~~--~--~---



mod_python help needed

2006-10-13 Thread doug

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

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: mod_python help needed

2006-10-13 Thread doug

1-link above 'is' the test server/

2-source is linked to svn code directly as described on
djangoproject.com

3- 404 is django's   see it here: http://oviparo.us/polls   -



Thanks Doug


On Oct 13, 7:57 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2006-10-13 at 11:30 +, 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.usReverse-engineering 
> > your configuration files, it looks like you must
> have a directory called /home/cottage/mysite4/ and the django source is
> either on the system python path (/usr/lib*/python*/site-packages/, for
> example) or also in /home/cottage.
>
> Are either of those two statements incorrect? If so, you need to tweak
> the PythonPath directive.
>
> When you receive a 404 page, I assume this is coming from Django? Not
> the default Apache 404 message? Assuming it is coming from Django, what
> is the error message you are seeing? Is it saying it cannot find a match
> for the URL you are submitting, or it cannot import a module, or
> something else?
>
> Your settings look basically sane, so my guess is that you have either
> made a spelling error somewhere (e.g. it should be /home/cotage/ instead
> of /home/cottage/ or something similar) or you haven't got the path to
> your Django project directory quite correct.
> 
> 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
-~--~~~~--~~--~--~---



mod_python

2006-10-13 Thread doug

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

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

2006-10-13 Thread doug

test server is running at http://oviparo.us  with configs listed- Doug

On Oct 13, 12:23 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> http://oviparo.us/redirects tohttp://oviparo.us/
>
> please post here your VirtualHost config. also, 1st thing to make sure,
> you are
> coming to right VirtualHost (so place some file in your htdocs to see
> if you can fetch it)
>
> 2nd step is make sure you have your  directives point to
> right place.


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



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: FastCgi / PostgreSQL: FATAL: Ident authentication failed for user "user_name"

2006-10-20 Thread doug

looks like same issure here:

http://groups-beta.google.com/group/django-users/browse_thread/thread/19ed1f82b5c80233/897f968eba507165?lnk=gst&q=authentication+failed+for+user&rnum=2#897f968eba507165

Doug

On Oct 19, 8:49 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2006-10-18 at 02:29 +, binberati wrote:[...]
>
>
>
> >   OperationalError at /
> >   FATAL: Ident authentication failed for user "user_name"
> > --
>
> > Surprisingly, I can succesfully connect to the db using either:
>
> > - psql - PostgreSQL interactive terminal
> > - django-admin.py shell
> > - django-admin.py dbshell
> > - django development server
> > - Navicat PostgreSQL from my own pc using ssh-tunnel
>
> > The only circumstance in which I cannot seem to connect to the db is
> > using the FastCgi instance, although it is configured to use the same
> > settings file as above...
>
> > [1] Can anybody shed a light on the difference between the FastCgi
> > context and the ones mentioned above? I suspect it must have something
> > to do with pg_hba.conf... but I can't see the difference between the
> > contexts.I would have a look at the user the fastcgi process is running as. 
> > The
> ident method of authentication looks at process-owner users, so that is
> important. In all the cases you mention above, *you* are the owner of
> the process trying to do the connection. In your fastcgi case, this is
> not necessarily true.
>
> > [2] How do I resolve this issue? :)Switch away from using ident 
> > authentication to password-based
> authentication, for example.
> 
> 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: Compiling mod_python 3.2.x on Ubuntu

2006-10-20 Thread doug

just finished setting up djanog-sandbox with ubuntu/
it is here:

http://oviparo.us

Doug


On Oct 20, 1:08 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I'm trying to compile version 3.2 of mod_python (required by django) on
> an Ubuntu Linux box.  (Ubuntu offers mod_python 2.4)
>
> The command ./configure --with-apxs=/usr/local/apache/bin/apxs doesn't
> work because that's not where the apxs files are.
>
> I have installed apache2-threaded-dev, which I understand installs the
> appropriate apxs files, but I can't seem to determine the path I should
> use instead of /usr/local/apache/bin/apxs  (I've cross-posted this to
> the Ubunutu forums.)
>
> Please excuse this rather newbie question. I'm not a programmer or
> Linux sysadmin by trade.
> 
> 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: Receiving emails via app

2008-10-26 Thread Doug B

poplib is pretty easy to work with:

def check_pop3(server,user,password):
import email,poplib,string
messages=[]
s=poplib.POP3(server)
s.user(user)
s.pass_(password)
resp, items, octets = s.list()
todelete=[]
for item in items:
id,size=item.split()
resp,text,octets = s.retr(id)
text = string.join(text, "\n")
message=email.message_from_string(text)
messages.append(message)
todelete.append(id) # flag for deletion
for id in todelete:
pass #s.dele(id)
s.quit()
return messages
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sending mass, yet personalised email newsletters using Django

2008-11-10 Thread Doug B

I can't claim best way, but the way we do it is to have a few django
models for storing the messages, and some help from the email, and
smptlib libraries.

Models:
Mailserver: model for storing connection information for connecting to
a standard smtp server, with mixin class using smtplib to provide smtp
connection.
BulkMail: Unrendered Template, and M2M relationship to users. Fk to
Mailserver.  This model generates Queued messages, in batches until
all recipients have a message queued (we trickle messages out).
QueuedMessage: Rendered message (pickled email.MimeMultipart object),
Fkeys to user, Bulkmail (if message was generated by the BulkMailer)
and Mailserver.

Every 15min a Bulk Mail cron to generate messages into the queue.
Depending on options one bulk mail object may trickle out the messages
until all are sent.
Every minute a cron runs to check for pending QueuedMessage objects,
and sends them to a real smtp server in batches [something like
mailserver_object.process_queue(priority=N,limit=100)]
Another cron using poplib to check the sending POP3 account for
unsubscribe requests, and for bounces using GNU Mailman (it's python,
and pretty simple to throw on your path and use the BouncerAPI for
bounce detection). Anything that isn't an unsub or bounce gets cloned/
forwarded to a human read pop account.
The crons do some checking using memcache okeys to make sure only one
process is doing mail at any one time, and no messages get stuck in a
loop.

All in all, it's been working great.  It takes very little time to
generate the messages and lets a real mail server handle the heavy
lifting/retries.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Different settings.py files for server and development

2008-11-11 Thread Doug Harris

One thing I've noticed is that some settings don't stick if I override
them in local_settings.py.

One key example is CACHE_BACKEND. Has anybody seen this sort of
behavior?


On Oct 23, 5:54 pm, felix <[EMAIL PROTECTED]> wrote:
> at the very bottom of settings.py :
>
> from local_settings import *
>
> this overwrites just the imported keys/values
>
> -flx
>
> On Thu, Oct 23, 2008 at 11:55 PM, Dana <[EMAIL PROTECTED]> wrote:
>
> > Hello everyone,
>
> > I know a form of this question has been asked before on this group but
> > I can't for the life of me find the thread.
>
> > I am wondering how I can have a generic settings.py file that contains
> > all my basic settings and then have a settings-local.py (or
> > whatever...) and have that contain custom settings such as DEBUG=True,
> > etc... Ideally the settings-local.py file would *only* have the custom
> > settings, and nothing else, but I cannot seem to get this to work. For
> > example:
>
> > In settings.py I would have default settings:
>
> > settings.py
> > ---
> > DEBUG = False
>
> > DATABASE_ENGINE = 'mysql'
>
> > DATABASE_NAME = 'something'
>
> > DATABASE_USER = 'root'
> > DATABASE_PASSWORD = ''
>
> > MEDIA_ROOT = '/home/user/media/'
> > MEDIA_URL = 'http://media.example.com/'
>
> > ADMIN_MEDIA_PREFIX = '/admin_media/'
>
> > INSTALLED_APPS = (
> >    
> > )
>
> > .. etc
>
> > ---
> > and in settings-local.py I would override the settings:
>
> > # settings-local.py
> > ---
> > DEBUG = True
>
> > DATABASE_USER = 'username'
> > DATABASE_PASSWORD = 'somethinghere123'
> > ---
>
> > I would like some way to have settings-local import my settings.py
> > file and then override specific settings. Anyone know how to do this
> > cleanly?
>
> > Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: help, ORM memory problems

2008-11-23 Thread Doug B

One thing that has bitten me more times than I care to remember is
forgetting to disable DEBUG in settings.py before processing large
datasets.  The SQL queries build up in connection.queries until the
process dies.  I ended up patching my django install to store queries
in a wrapper around buffer so that only the 200 most recent queries
were stored instead of ALL of them.  Aside from making sure debugging
is off/disabled I end up stepping over in batches:

ids=[o["id"] for MyModel.objects.all().values("id")]
count=len(ids)
steps=1000
for n in range(steps,count+steps,steps):
lo,hi= n-steps, n
objects=MyModel.objects.filter(pk__in=ids[lo:hi])
function_that_processes_batch(objects)

I've imported data sets of around 80k like this, and the memory usage
is usually less than 200m.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: I don't even know where to begin writing this template-tags

2009-01-21 Thread Doug B

I went the hideous route, but tried to make it general enough I could
reuse.  I'm still on .96, but it shouldn't be too much trouble to make
it work with 1.0.

In [2]: template.Template("{% load kwtag %}{% do_kwtagtest foo foo=bar
%}").render(template.Context())
Out[2]: "['foo']{'foo': 'bar'}"

In [6]: template.Template("{% load kwtag %}{% do_kwtagtest foo foo=bar
%}").render(template.Context({'foo':'blue'}))
Out[6]: "['blue']{'foo': 'bar'}"

In [7]: template.Template("{% load kwtag %}{% do_kwtagtest foo foo=bar
%}").render(template.Context({'foo':'blue','bar':'brown'}))
Out[7]: "['blue']{'foo': 'brown'}"

The parsing is not perfect, but it's usable for most simple stuff I
needed to do with it.  Might be of some use.

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



Re: Dynamic routing

2009-07-13 Thread Doug B

It's not very efficient, but it's possible.  I just finished up an app
where dynamic urls was an unfortunate requirement, but simple to
implement.

A view is just a function within which can call another view, so it's
easily possible to have a catchall view that captures the url (using
the normal static routing), fetches uncompiled regex strings->view
name mappings from a source (database, file, etc) and applies those
regexes until one matches. Then have the catchall/dispatcher view call
real view function associated with the regex that matched - passing on
the request object  and captured parameters just like the static url
dispatcher would.

For the app where I needed this functionality, most of the urls were
done with static mapping - only a certain pattern are set to do a
dynamic match.  I also decided to store them in a file via the
ConfigParser module rather than in the database, assuming this would
probably be faster but I haven't gotten around to verifying that
assumption.  The more you can leave static, the better.



On Jul 13, 12:57 pm, Maksymus007  wrote:
> Its possible to use dynamic (database based maybe) routing, instead of
> static one?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Concurrent Web Access and Edits

2009-08-11 Thread Doug Blank

New Django user here with a question about the client side: Is there
built-in support for dealing with concurrent edits? I'm not referring
to the database issues (locking, etc) but is there Django support for
handling a request to access or edit data for which another user is
editing?

I'm thinking about simple timestamps, detection of changed data, and
showing the user options to abort, overwrite, or re-edit.

Does one have to implement this for saving data? Anything I should
read that covers this or related topic? I couldn't find anything on
the Django site, nor in this forum.

Thanks for any pointers!

-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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Render template tags together

2009-08-16 Thread Doug B

I don't know if it's the best approach or not, but what I've done in
the past is to have the first call to the tag do any expensive stuff
and store it in a dict under a special name in the context (I usually
use __tagname).  Subsequent calls to the tag use the data from the
context variable rather than rebuilding it each time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bulk data insert

2009-08-20 Thread Doug Blank

On Aug 20, 2:50 pm, Alex Gaynor  wrote:
> On Thu, Aug 20, 2009 at 1:46 PM, Abiel wrote:
>
> > Is there an efficient way to use Django models to load a large number
> > of records into a database without falling back on raw SQL? Creating a
> > large number of model objects and then saving each one individually is
> > very slow (I imagine Django is running INSERT and COMMIT each time?).
>
> > Thanks very much.
>
> Django doesn't currently support any form of bulk insert.  Using raw
> SQL is your best option at this point.
>

I also am trying to do a bulk load, but has to be written in Python.
It is a two pass loading procedure, where the first pass could be done
with the indexes turned off, and the second pass with them on.

Is there a way to disable indexes momentarily and then turn them back
on? Or can I manage the transactions to do saves in bulk in the first
pass?

Thanks for any pointers!

-Doug

> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bulk data insert

2009-08-20 Thread Doug Blank
On Thu, Aug 20, 2009 at 10:40 PM, Benjamin Sergeant wrote:

>
> (the answer was already sent, raw SQL, anyway)
>
> (with postgresql) I would try to load just a small bit of datas with
> the slow create django object / save it process, then do a pg sql
> dump, and look at the sql that pg dump generated. Then code a python
> script that generate that.
>
> And then do a pg load which is super fast.
>

Let me be more specific about what I am looking for: I am writing an
application that could have any django-supported backend. I have a two pass
importer that fills in tables (the program does a lot of processing and data
manipulation in these import passes). The application is written in django.
I am looking for a way to speed up the first pass of the process that
doesn't need indexes (of course, I'd speed up all of it if I could).

I do not want to rewrite what I have as raw SQL, I am just looking for
anything that I can do, such as turn off indexing, write to the db in
batches, or similar django-level optimizations.

I don't think what you mentioned can help in this situation, right?

-Doug



>
> - Benjamin
>
>
>
>
> On Thu, Aug 20, 2009 at 7:08 PM, Doug Blank wrote:
> >
> > On Aug 20, 2:50 pm, Alex Gaynor  wrote:
> >> On Thu, Aug 20, 2009 at 1:46 PM, Abiel wrote:
> >>
> >> > Is there an efficient way to use Django models to load a large number
> >> > of records into a database without falling back on raw SQL? Creating a
> >> > large number of model objects and then saving each one individually is
> >> > very slow (I imagine Django is running INSERT and COMMIT each time?).
> >>
> >> > Thanks very much.
> >>
> >> Django doesn't currently support any form of bulk insert.  Using raw
> >> SQL is your best option at this point.
> >>
> >
> > I also am trying to do a bulk load, but has to be written in Python.
> > It is a two pass loading procedure, where the first pass could be done
> > with the indexes turned off, and the second pass with them on.
> >
> > Is there a way to disable indexes momentarily and then turn them back
> > on? Or can I manage the transactions to do saves in bulk in the first
> > pass?
> >
> > Thanks for any pointers!
> >
> > -Doug
> >
> >> Alex
> >>
> >> --
> >> "I disapprove of what you say, but I will defend to the death your
> >> right to say it." -- Voltaire
> >> "The people's good is the highest law." -- Cicero
> >> "Code can always be simpler than you think, but never as simple as you
> >> want" -- Me
> > >
> >
>
> >
>

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



Re: db api

2009-08-21 Thread Doug Blank
On Fri, Aug 21, 2009 at 4:22 AM, luca72  wrote:

>
> I have solved using :
> Model.object.filter(id=2)values('columnname')
>

Note that it should have a dot:

Model.object.filter(id=2).values('columnname')

and that returns the item you want in a list. The proper way to do that is:

Model.object.get(id=2).columnname

where get returns an object, and all of the columnnames are just attributes
of it.

-Doug


>
> Thanks
>
> Luca
>
> On 21 Ago, 10:14, luca72  wrote:
> > Thanks for your reply but i get this error:
> > Model object has no attribute 'values'
> >
> > Thanks
> >
> > On 21 Ago, 09:42, Kenneth Gonsalves  wrote:
> >
> > > On Friday 21 Aug 2009 1:00:32 pm luca72 wrote:
> >
> > > > how i can write this with the djago db api:
> > > > SELECT "column name" from "table_name" where "id"=2
> >
> > > Model.objects.get(id=2).values('columnname',)
> > > --
> > > regards
> > > kghttp://lawgon.livejournal.com
> >
>

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



Re: Dates with varying specificity?

2009-08-23 Thread Doug Blank
On Sat, Aug 22, 2009 at 12:24 PM, ringemup  wrote:

>
> Has anyone here ever written an application that needed to be able to
> take a date field where the month or day was sometimes but not always
> known?  How would you handle this?  Using separate day/month/year
> fields instead of a DateField seems to sacrifice a lot of convenience
> and usability.
>

We've just begun to develop a web front-end to an open source genealogy
program (http://gramps-project.org) and are looking into this issue. We have
a sophisticated date object that includes different calendars (Julian,
Gregorian, etc) and date specifiers ("about 1863", "between Jan 1, 1734 and
Feb 1735") and more. We'll probably develop our own Model so that we can
treat these with some of the same convenience as DateField, but handle the
complexity from behind.

We don't have any of the date model coded yet, so this is just an FYI.

-Doug


>
> Thanks!
> >
>

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



Re: newbye question

2009-09-14 Thread Doug Blank
On Mon, Sep 14, 2009 at 7:17 AM, Nicola Manica wrote:

> Hi, I'm a student that try to learn geodjango.
> I have the following code in one view:
> ...
> for t_path in path.the_geom:
>   print t_path.json
>   print t_path.wkt
>   print t_path.kml
> ...
>
> path.the_geom is a multilinestring.
> The output that I obtain is
> ...
> { "type": "LineString", "coordinates": [ [ 11.128620, 46.056345 ], [
> 11.128456, 46.056653 ], [ 11.128398, 46.056771 ] ] }
> LINESTRING (11.12862023 46.056345100015, 11.12845566
> 46.05665337, 11.12839815 46.05677077)
> 11.1286202,46.0563451,0 11.1284556,46.0566533,0
> 11.1283982,46.056771,0
> 
>
> json is correct and also wkt.
> But kml? Is it correct? Why some points have coordinates equal to zero?
> Thank for your help
>

Looks like x,y,z coordinates if I were guessing. If you had elevation data,
maybe it wouldn't be zeros.

-dsb


> Nicola
>
>
>
>
>
> >
>

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



Re: Skinning a project with pre-designed DIV?

2009-03-30 Thread Doug B

Django is pretty flexible, so it's impossible to say exactly how to
integrate with your existing design since the original developer could
have done the template layout in a number of different ways.  Since
the development process is a bit different that php, you might want to
step through the tutorial in the documentation - even if all you plan
on doing is changing the html.  The short amount of time spent there
will pay off.

If you're lucky, there may be a single wrapper template that most/all
of the other pages extend and you can simply modify the base template
with the new design.  In any case, I'd suggest reading the template
language docs, specifically the part about Template Inheritance.  From
there you should be able to look at the html/template files in your
existing project and be able to see how to merge your design.  You'll
probably want to run the django development server to view the
rendered pages as you work on the templates.

http://docs.djangoproject.com/en/dev/topics/templates/#id1

As an example of the process, you might look at the section of the
djangobook that has to do with overriding the built in admin-app
templates "Customizing Admin Templates".  There is no guarantee your
custom app will have a similar template layout, but it should be a
good conceptual overview.

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



Re: how to django to request a page of the other domain

2009-04-01 Thread Doug B

It might be better to use the rewrite/proxy capability of your
webserver rather than try to proxy using django.  If you do end up
trying to do it in python, I found pycurl to be much easier to deal
with for any requests requiring cookies, authentication, or anything
besides a simple url get despite being it being advertised as having a
'somewhat steep learning curve'.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model A imports Model B imports Model A - I'm completely lost as to how to get around circular imports

2009-04-05 Thread Doug B

Take a look at this part of the documentation:

http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects

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



Re: Template Variables as Indexes

2009-04-24 Thread Doug B

Might not be the easiest way, but you could use a custom filter:

def formsbyfield(forms,field):
""" Given a list of similar forms, and a field name,
return a list of formfields, one from each form.
"""
return [form.fields.get(field,'') for form in forms]
register.filter('formsbyfield',formsbyfield)

{% for fieldname in forms.0.fields.keys %}

{% for ff in forms|formsbyfield:fieldname %}
{{ff}}
{% endfor %}

{% endfor %}

Something like that should work, though I haven't tested it.


On Apr 24, 11:18 am, NewSpire  wrote:
> I have a list of forms, all of the same type, where I would like to
> list each form side by side with the fields listed vertically.  The
> root of the problem is that I need to use a template variable as an
> index on another template variable.  Something like this.
>
> 
> {% for field in forms.0 %}
> 
>     {{ field.label }}:
>     {% for form in forms %}
>         {{ form.field.{{ forloop.parentloop.counter0 }} }}
>     {% endfor %}
> 
> {% endfor %}
> 
>
> The outer loop if looping over form.0 to create a row for each set of
> fields and the labels.  The inner loop is providing the list of fields
> for each row.  Does anybody see a way to do something like this?
>
> Thanks!
> Andy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to handle database down time gracefully?

2009-04-24 Thread Doug B

This has been on my todo list of a while now, so I thought I'd trying
to figure it out.

I -think- the proper way to go about this would be in a custom
middleware with a process_exception handler that checks to see if the
exception is an instanace of the database defined exceptions.  Looking
in django/db/__init__.py shows "DatabaseError" gets assigned according
to backend, so I assume it's safe to use as a check regardless of
database settings.

Turning off my database any playing I did a check on the exception
generated when the database was down, and it looks ok - atleast for
postgres:

from django.db import DatabaseError

isinstance(exception,DatabaseError) returned true.

So I though I could add this method to a middleware class:

def process_exception(self,request,exception):
# In case django doesn't send use the original request
from django.db import DatabaseError
if isinstance(exception,DatabaseError):
return HttpResponse("Database offline for maintenance - please
try back later")
return None

Unfortunately, process_excpetion() never seems to get called.

Searching track shows a ticket that explains the problem. Exceptions
in middleware don't hit the middlware exception handlers.
Unfortunately one of my middlware does hit the database on each call,
so I had to modify my middlware to catch the exception and return a
response object.

http://code.djangoproject.com/ticket/6094

Other than making sure to handle any middlware DB exceptions manually
it seems to be working ok.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Disabling PRG Pattern

2009-04-26 Thread Doug B

Maybe the APPEND_SLASH setting is causing it (along with a missing
slash at the end of your url)?

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



Re: Client requests Django capacities

2009-05-06 Thread Doug B

There is no way you can give an answer based on an application that
doesn't exist, and a server that doesn't exist.  What I would do is
give them real numbers based on an application you -can- test.  Build
a tiny Django application that does something resonably representitive
of what the real application average page would be, and use one of the
testing tools to generate your own data.  Maybe a simple virtualbox/
vmware image you can archive.  Document the test, configuration,
equipment, and code for a footnote reference.  If you give them real
data, and fully disclose how you got it gives them what they want and
covers your ass.

Something like this:
http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/


On May 6, 9:52 am, Roberto Cea  wrote:
> I am in the process of signing a contract to develop a website for a
> fairly large IT company using Django. They requested that the contract
> nclude:
>
> 1) number of concurrent visitors that the site will support
> 2) maximum response times for typical requests
>
> I've explained that both items will depend finally on the server
> hardware, which they will provide, but they still want some ballpark
> figures.
> I realize that a precise answer would depend on the specifics of how
> the site is programmed, but wonder if anybody has any idea or
> experience answering this kind of question?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



settings.configure vs DJANGO_SETTINGS_MODULE

2009-10-13 Thread Doug Blank

I'm trying to use django without resorting to setting the environment
variable, by doing this:

from django.conf import settings
import mysettings
settings.configure(mysettings, DEBUG=True)

The mysettings.py originally just contained those in the default
settings.py file.

However, I keep getting errors claiming that my module is missing
settings, such as this error:

...
  File 
"/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py",
line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
  File 
"/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py",
line 172, in _fetch
for localepath in settings.LOCALE_PATHS:
  File "/usr/lib/python2.6/site-packages/django/utils/functional.py",
line 273, in __getattr__
return getattr(self._wrapped, name)
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py",
line 130, in __getattr__
return getattr(self.default_settings, name)
AttributeError: 'module' object has no attribute 'LOCALE_PATHS'

I've added a bunch of settings with their defaults after I get such an
error, such as these:

DATABASE_OPTIONS = ''
URL_VALIDATOR_USER_AGENT = ''
DEFAULT_INDEX_TABLESPACE = ''
DEFAULT_TABLESPACE = ''
CACHE_BACKEND = 'locmem://'
TRANSACTIONS_MANAGED = False

and it will run further into some new code, until django looks up
another setting, and it isn't there.

Everything works fine if I set the DJANGO_SETTINGS_MODULE env variable.

I've read:

http://docs.djangoproject.com/en/dev/ref/settings/

and the older version for 1.0, but they both suggest that what I'm
doing is correct.

I'm using sqlite and Django-1.1-4.fc11.noarch under Fedora 11.

Is this a bug, or am I doing something wrong?

Thanks for any insight!

-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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: settings.configure vs DJANGO_SETTINGS_MODULE

2009-10-14 Thread Doug Blank

On Tue, Oct 13, 2009 at 10:06 PM, Doug Blank  wrote:
> I'm trying to use django without resorting to setting the environment
> variable, by doing this:
>
> from django.conf import settings
> import mysettings
> settings.configure(mysettings, DEBUG=True)
>
> The mysettings.py originally just contained those in the default
> settings.py file.
>
> However, I keep getting errors claiming that my module is missing
> settings, such as this error:
>
> ...
>  File 
> "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py",
> line 194, in translation
>    default_translation = _fetch(settings.LANGUAGE_CODE)
>  File 
> "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py",
> line 172, in _fetch
>    for localepath in settings.LOCALE_PATHS:
>  File "/usr/lib/python2.6/site-packages/django/utils/functional.py",
> line 273, in __getattr__
>    return getattr(self._wrapped, name)
>  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py",
> line 130, in __getattr__
>    return getattr(self.default_settings, name)
> AttributeError: 'module' object has no attribute 'LOCALE_PATHS'
>
> I've added a bunch of settings with their defaults after I get such an
> error, such as these:
>
> DATABASE_OPTIONS = ''
> URL_VALIDATOR_USER_AGENT = ''
> DEFAULT_INDEX_TABLESPACE = ''
> DEFAULT_TABLESPACE = ''
> CACHE_BACKEND = 'locmem://'
> TRANSACTIONS_MANAGED = False
>
> and it will run further into some new code, until django looks up
> another setting, and it isn't there.
>
> Everything works fine if I set the DJANGO_SETTINGS_MODULE env variable.
>
> I've read:
>
> http://docs.djangoproject.com/en/dev/ref/settings/
>
> and the older version for 1.0, but they both suggest that what I'm
> doing is correct.
>
> I'm using sqlite and Django-1.1-4.fc11.noarch under Fedora 11.
>
> Is this a bug, or am I doing something wrong?
>
> Thanks for any insight!
>
> -Doug
>

I was able to make it through all of the tests with my sqlite backend
by adding all of these default values:

DATABASE_OPTIONS = ''
URL_VALIDATOR_USER_AGENT = ''
DEFAULT_INDEX_TABLESPACE = ''
DEFAULT_TABLESPACE = ''
CACHE_BACKEND = 'locmem://'
TRANSACTIONS_MANAGED = False
LOCALE_PATHS = tuple()

But I'm wondering if I change the backend if there will be other
missing values.

Do people not use settings.configure()? I would think that most people
would not want to have to rely on an environment variable.

-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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using variables as keywords in QuerySet

2009-10-21 Thread Doug Blank

On Wed, Oct 21, 2009 at 5:12 AM, Arthur Metasov  wrote:
>
> 2009/10/21 valler <180...@gmail.com>:
>>
>> Hello. I want to know, if something like that possible:
>>  MyModel.objects.filter(name__contains='foo',status__exact='bar') =>
>> It's OK.
>>
>> But I want to use dynamic keyword generation, like that:
>>  a='name'
>>  b='status'
>>  MyModel.objects.filter(a__contains='foo',b__exact='bar')
>>
>> Is it possible somehow?
>
> a='name'
> b='status'
> keyword_arguments = {}
> keyword_arguments[a+'__contains']='foo';
> keyword_arguments[b+'__exact']='bar';
> MyModel.objects.filter(**keyword_arguments)
>

Or, more concisely as:

MyModel.objects.filter(**{a+'__contains':'foo', b+'__exact':'bar';})

-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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Automatic swapping of field data?

2009-11-18 Thread Doug Blank
Django users,

I have data that needs to be handled in two different manners,
depending on if the user has certain permissions or not. For example,
if a record is marked "private" and a user is not permitted, I want to
substitute the word "PROTECTED" for a particular field's value.

Now, of course I realize that each and every place I refer to
table.fieldname I could wrap a protection around that, either in my
Python code, or in my templates.

What I'm really looking for is something closer to the model code so
that I can be assured that no private data accidentally slips out.
Does Django have any built in support that does this, or could be
adapted to do this?

Any ideas appreciated!

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: Automatic swapping of field data?

2009-11-19 Thread Doug Blank
On Thu, Nov 19, 2009 at 4:36 PM, Preston Holmes  wrote:
> There are some details left out of how you want this to look.
>
> The lower the level you try to make an object self protecting, the
> trickier it's going to be.
>
> The sweet spot I think here is a custom manager that adds a protect
> filter, and perhaps a subclass of ModelForm if you need this in
> forms.  The custom manager method would take a user obj as a
> parameter, then loop through the objects in the queryset and modify
> protected fields as needed.
>
> http://www.djangoproject.com/documentation/models/custom%5Fmanagers/
> http://www.djangosnippets.org/snippets/562/

Thanks for the links! These got me thinking along a line of thought,
and I came up with something like:

class MyModel(models.Model):
...
def __getattribute__(self, item):
if item == "fieldname":
return ""
else:
return super(MyModel, self).__getattribute__(item)

In the getattribute method, I can check some conditions (ie, to see if
the user is logged in), and provide my own data if not. This way, I
can write my django code and never have to worry that the value of
fieldname will ever accidentally not be protected as this is the only
way to get it.

See any problems with this (other than taking a small hit on every
field access)?

-Doug

> On Nov 18, 4:17 pm, Doug Blank  wrote:
>> Django users,
>>
>> I have data that needs to be handled in two different manners,
>> depending on if the user has certain permissions or not. For example,
>> if a record is marked "private" and a user is not permitted, I want to
>> substitute the word "PROTECTED" for a particular field's value.
>>
>> Now, of course I realize that each and every place I refer to
>> table.fieldname I could wrap a protection around that, either in my
>> Python code, or in my templates.
>>
>> What I'm really looking for is something closer to the model code so
>> that I can be assured that no private data accidentally slips out.
>> Does Django have any built in support that does this, or could be
>> adapted to do this?
>>
>> Any ideas appreciated!
>>
>> -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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>
>

--

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




MemoryError when adding a lot of data

2009-11-20 Thread Doug Blank
I'm filling my Django tables with data through a regular Python
program (not through the browser). After it runs for a few hours, I
get:

10557896: ERROR: gramps.py: line 121: Unhandled exception
Traceback (most recent call last):
  ...
event = models.Event.objects.get(handle=ref)
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 120, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 300, in get
num = len(clone)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 81, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 238, in iterator
for row in self.query.results_iter():
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 287, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 2369, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
line 22, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py",
line 217, in last_executed_query
return smart_unicode(sql) % u_params
MemoryError

The line that looks suspicious to me is the "self._result_cache =
list(self.iterator())". Does it look like that might be the problem?
I'm not manually doing anything other than adding data, changing data,
and calling .save() (eg, I'm not doing anything with transactions in
my code).

I looked at the chapter on cache from the book:

http://www.djangobook.com/en/beta/chapter14/

but I'm not sure how this is related. Although, if there was a Python
command to turn off caching while importing, that might be something
to try.

Any ideas appreciated,

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: MemoryError when adding a lot of data

2009-11-20 Thread Doug Blank
On Fri, Nov 20, 2009 at 6:32 AM, Doug Blank  wrote:
> I'm filling my Django tables with data through a regular Python
> program (not through the browser). After it runs for a few hours, I
> get:
>
> 10557896: ERROR: gramps.py: line 121: Unhandled exception
> Traceback (most recent call last):
>  ...
>    event = models.Event.objects.get(handle=ref)
>  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line 120, in get
>    return self.get_query_set().get(*args, **kwargs)
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 300, in get
>    num = len(clone)
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 81, in __len__
>    self._result_cache = list(self.iterator())
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 238, in iterator
>    for row in self.query.results_iter():
>  File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
> line 287, in results_iter
>    for rows in self.execute_sql(MULTI):
>  File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
> line 2369, in execute_sql
>    cursor.execute(sql, params)
>  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
> line 22, in execute
>    sql = self.db.ops.last_executed_query(self.cursor, sql, params)
>  File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py",
> line 217, in last_executed_query
>    return smart_unicode(sql) % u_params
> MemoryError
>
> The line that looks suspicious to me is the "self._result_cache =
> list(self.iterator())". Does it look like that might be the problem?
> I'm not manually doing anything other than adding data, changing data,
> and calling .save() (eg, I'm not doing anything with transactions in
> my code).
>
> I looked at the chapter on cache from the book:
>
> http://www.djangobook.com/en/beta/chapter14/
>
> but I'm not sure how this is related. Although, if there was a Python
> command to turn off caching while importing, that might be something
> to try.
>
> Any ideas appreciated,
>
> -Doug
>

Some additional data:

I'm using Django 1.1 on Fedora11 with sqlite backend. I get the same
kind of spiking of memory usage if I just enter:

>>> Person.objects.all().delete()

Memory usage continues to grow, and it doesn't seem to be able to be
garbage collected. What could cause this? Anything I can set or issue
to make Django clean up/use less  memory? I am running out of memory,
just deleting the data! Something seems to be very wrong...

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: MemoryError when adding a lot of data

2009-11-21 Thread Doug Blank
On Fri, Nov 20, 2009 at 10:22 PM, Karen Tracey  wrote:
> On Fri, Nov 20, 2009 at 6:19 PM, Doug Blank  wrote:
>>
>> Some additional data:
>>
>> I'm using Django 1.1 on Fedora11 with sqlite backend. I get the same
>> kind of spiking of memory usage if I just enter:
>>
>> >>> Person.objects.all().delete()
>>
>> Memory usage continues to grow, and it doesn't seem to be able to be
>> garbage collected. What could cause this? Anything I can set or issue
>> to make Django clean up/use less  memory? I am running out of memory,
>> just deleting the data! Something seems to be very wrong...
>>
>
> Are you running this script with settings that have DEBUG set to True?

I did have DEBUG = False in settings.py, but I also confirmed that it
was the connections that were growing. On further inspection, I found
I had this tucked away in my non-browser, reloadable Python code:

from django.conf import settings
import web.settings as default_settings
try:
settings.configure(default_settings, DEBUG=True)
except RuntimeError:
# already configured; ignore
pass

which was causing part of the problem. It does seem that:

Table.objects.all().delete()

is "leaking" memory (eg, continues to use memory) and is very slow.
I'm trying to find a better (faster, less memory) method similar to
the manage.py command sql_flush...

Thank you very much for the pointer! Part of the problem solved...

-Doug

> See:
> http://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory
>
> Karen
ooglegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=.
>

--

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




Re: MemoryError when adding a lot of data

2009-11-21 Thread Doug Blank
On Sat, Nov 21, 2009 at 7:44 AM, Doug Blank  wrote:

[snip]

> It does seem that:
>
> Table.objects.all().delete()
>
> is "leaking" memory (eg, continues to use memory) and is very slow.
> I'm trying to find a better (faster, less memory) method similar to
> the manage.py command sql_flush...

Is this a "better" way to flush a table, programmatically?

from django.db import connection, transaction
models = [Person, User, ...]
cursor = connection.cursor()
flush_tables = []
for model in models:
flush_tables.append(model._meta.db_table)
statements = connection.ops.sql_flush(no_style(),
  flush_tables,

connection.introspection.sequence_list())
for statement in statements:
cursor.execute(statement)
transaction.commit_unless_managed()

It would be nice if flush() were a method on Model, yes?

-Doug

> Thank you very much for the pointer! Part of the problem solved...
>
> -Doug
>
>> See:
>> http://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory
>>
>> Karen

--

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




Re: form fields slicing

2009-11-23 Thread Doug Blank
On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  wrote:
> why this piece of code doesn't work?
>
> {% for field in form|slice:":2" %}
>
> the result is iterating over all fields, not just the first two fields

Perhaps break this up into two parts?

{% with form|slice:":2" as formslice %}
(% for field in formslice %}

-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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>
>

--

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




Re: Model inheritance - filtering base model only

2009-11-23 Thread Doug Blank
On Mon, Nov 23, 2009 at 9:09 AM, lfrodrigues  wrote:
> I guess this solution works but for +50 the performance should be
> terrible...
>
> Shouldn't django have some option for this?

Could you set a field's value which is true for one, and false for the
other? Otherwise, could you just have two tables?

I wonder if ContentType could help?

obj_type = ContentType.objects.get_for_model(player)
source_refs = PlayerM.filter(object_type=obj_type)

(object_type gets created with generic relations)

-Doug

> On 23 Nov, 04:53, Preston Holmes  wrote:
>> Perhaps there is a more efficient way, but in my quick test, one can't
>> filter() a queryset based on __class__ of the model, but seems one can
>> manually filter it afterwords:
>>
>> qs = Player.objects.all()
>> for i,obj in enumerate(qs):
>>     if obj.__class__ != Player:
>>         del(qs[i])
>>
>> On Nov 22, 4:32 pm, lfrodrigues  wrote:
>>
>> > Hello,
>>
>> > I have these models:
>>
>> > class Player(models.Model):
>> >     .
>>
>> > class PlayerM(Player):
>> >     ...
>>
>> > If I do PlayerM.objects.all() e get all PlayerM objects and for
>> > Player.objects.all() I get all Player and PlayerM as expected.
>>
>> > How can get only the objects of type Player (only retrieve the objects
>> > that were created with Player() constructor)?
>>
>> > Regards,
>>
>> > Luis
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>
>

--

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




Re: delete every record in a table?

2009-12-04 Thread Doug Blank
On Fri, Dec 4, 2009 at 3:44 PM, Daniel Roseman  wrote:
> On Dec 4, 8:37 pm, Phlip  wrote:
>> Django users:
>>
>> I only ask the question to help improve my esthetics, but others might
>> need a performance boost here.
>>
>> How to delete every record in a table?
>>
>> A related question - how to delete every record matching a filter, out
>> of one internal SQL command?
>>
>> The brute-force way:
>>
>>   for p in Plutocrat.objects.all():  p.delete()
>>
>> Is there a way to do that in one method call? and could such a method
>> call only send one SQL command?
>>
>
> Yes:
> Plutocrat.objects.all().delete()

I found that quite slow. If you want to stay DB agnostic, I came up with this:

   from django.db import connection, transaction
   models = [Person, User, ...]
   cursor = connection.cursor()
   flush_tables = []
   for model in models:
   flush_tables.append(model._meta.db_table)
   statements = connection.ops.sql_flush(no_style(),
   flush_tables,
   connection.introspection.sequence_list())
   for statement in statements:
   cursor.execute(statement)
   transaction.commit_unless_managed()

I don't know of any bad side effects...

-Doug

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

--

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




Re: import twice when run test

2009-12-09 Thread Doug Blank
On Thu, Nov 26, 2009 at 6:01 AM, Tom Evans  wrote:
> On Thu, Nov 26, 2009 at 2:35 AM, fallhunter  wrote:
>>
>> i have this code in my tests.py:
>>
>> from models import *
>>
>> and in the models.py I have a signal handler and register it with
>>
>> post_save.connect( post_save_note, sender=Note )
>>
>> and when i run test with ./manage.py test main
>>
>> I found the signal handler was registered twice and executed twice,
>> and I found it's because the models was imported twice.
>>
>> can't i put "from models import *" in the test code? what should i do?
>>
>
> This happens if you import the same file using two different names. Eg, here
> you are importing it as 'from models import *'. In some other part of your
> code, you probably have 'from foo.models import *'. Python treats them as
> two different files, and hence the signal is attached twice.

BTW, this is not true for regular Python imports:

$ cat > mytest.py
print "hello"
$ python
>>> import mytest
hello
>>> from mytest import *
>>>
>>> import mytest as yourtest
>>>

It may be loaded twice (or more) by different threads or by another
import mechanism (which seems to be the case here):

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

See section on "Help, post_save seems to be emitted twice for each save!"

-Doug

> Remove/rework the spurious import, and everything will work.
>
> Cheers
>
> Tom
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Using Forms to display and edit?

2009-12-15 Thread Doug Blank
Django users,

I'm wrestling with how to best create HTML pages that can either be
used for displaying or editing data. That is, I'd like the field's
values to appear as text in display mode, but in their widgets when in
edit/add mode. It appears that Django wasn't designed to do this: the
fields always appear in their widgets (eg, text input, text area,
etc).

Is there a common technique for handling this, short of using forms
for one, and not the other?

I was thinking of a custom templatetag filter that could be used for
every form field, like:

{{ form.field_name|render_field:mode }}

where render_field would either return the field's HTML widget, or
just the value as text, based on the mode.

Have I missed something, or is this a viable solution?

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Using Forms to display and edit?

2009-12-15 Thread Doug Blank
On Tue, Dec 15, 2009 at 5:45 PM, Margie Roginski
 wrote:
> When I want to just display data in a form (as opposed to letting user
> edit it), I create a specialized widget.  For example, I have a model
> that has multiple datetime fields, and I don't want the user to be
> able to edit them, but I do want to display their values.  Here's a
> widget I use where you pass it some when you intiailize it (the task
> it's operating on and the field name to display).  Its render() method
> just renders the specified field:
>
> class TaskForm_DisplayDateTimeWidget(widgets.Widget):
>
>    def __init__(self, task=None, fieldNameToDisplay=None, attrs =
> {}):
>        self.task = task
>        self.fieldNameToDisplay=fieldNameToDisplay
>        super(TaskForm_DisplayDateTimeWidget, self).__init__(attrs)
>
>    def render(self, name, value, attrs=None):
>        rendered = ""
>        if self.task and self.fieldNameToDisplay:
>            dateVal = getattr(self.task, self.fieldNameToDisplay)
>            if dateVal:
>                rendered = mark_safe("%s" % date(dateVal, "%s %s" %
> (settings.DATE_FORMAT, settings.TIME_FORMAT)))
>
>        return rendered
>
> In my form, which is a model form, I declare the field like this in
> "class global" area (l the area that is in the class but not in any
> method:
>
>    displayModified = DisplayField(label="modified", widget =
> DisplayDateTimeWidget, required=False)
>
> Then in __init__() I do this:
>
>    instance = kwargs.get("instance")
>    if instance:
>            self.fields["displayModified"].widget =
> DisplayDateTimeWidget(task=instance, fieldName="displayModified")
>
> My form is a modelForm, so I do not put this field in Meta.fields, as
> that would cause django to do some extra stuff like atempt to clean
> the field, which doesn't make any sense since there is no input.  So
> basically I'm using all the form and widget infrastructure that django
> supplies, but I'm just not sending any inputs associated with these
> fields. I've seen a lot of people complain about django's lack of
> "read only" fields, but it seems to me that being able to write your
> own widgets and fields gives you total flexibility and that there's no
> need for an actual "read only" field.  My experience is that as soon
> as I got past the basics in my project and wanted to do more complex
> html/css, I never wanted to use the default rendering for any kind of
> field, and read only fields are just one case of this.
>
> In your case you say you sometimes want to create the fields as
> editable and soemtimes not.  In your form you could look at a GET
> variable that identifies whether you want fields to be editable or not
> and then either create your field with a different widget based on
> that GET variable, or even modify what your widget does based on that
> GET variable (ie, pass the value of the GET variable in as a parameter
> to the widgets __init__() method so it can do different stuff based on
> it at render time.
>
> Anyway, hope this helps and am curious if others use this same
> mechanism or if there is some alternate preferred approach.
>
> Margie

Thanks Margie for this example. I may come to something similar to
this, but for the time being I think I'll just put a filter in the
template. That way, I'll have all of the elements there (errors,
display information) for all of the modes (display, edit, and add).
I'll see how far I can go with this method before having to resort to
a more substantial widget-swap.

It does seem that this is an area of Django that could use some thinking...

-Doug

>
>
> On Dec 15, 4:01 am, Doug Blank  wrote:
>> Django users,
>>
>> I'm wrestling with how to best create HTML pages that can either be
>> used for displaying or editing data. That is, I'd like the field's
>> values to appear as text in display mode, but in their widgets when in
>> edit/add mode. It appears that Django wasn't designed to do this: the
>> fields always appear in their widgets (eg, text input, text area,
>> etc).
>>
>> Is there a common technique for handling this, short of using forms
>> for one, and not the other?
>>
>> I was thinking of a custom templatetag filter that could be used for
>> every form field, like:
>>
>> {{ form.field_name|render_field:mode }}
>>
>> where render_field would either return the field's HTML widget, or
>> just the value as text, based on the mode.
>>
>> Have I missed something, or is this a viable solution?
>>
>>

Re: Custom Django-Admin commands

2009-12-21 Thread Doug Blank
On Mon, Dec 21, 2009 at 8:10 PM, Justin Steward  wrote:
> Hi all,
>
> I've written a custom command to use with manage.py, and from the root
> of the project directory, it works great.
>
> But the problem is, this command is almost never going to be called
> from within the project directory.
>
> (hoping the spacing doesn't get too mangled when I send this)
> /home/
>  user/ <- ""/home/user/proj/manage.py custom" command doesn't exist.
>     proj/  <- "/home/user/proj/manage.py custom" works
>       manage.py
>       app/
>         management/
>           commands/
>             custom.py
>
> Is there something I'm missing?

You probably just need to set your PYTHONPATH:

cd /home/user
PYTHONPATH=proj python proj/manage.py custom

-Doug

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

--

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




Re: super() argument 1 must be type, not None

2009-12-23 Thread Doug Blank
On Wed, Dec 23, 2009 at 11:15 AM, TiNo  wrote:
> On Wed, Dec 23, 2009 at 16:53, Bill Freeman  wrote:
>>
>> Are you sure that Lid is defined in this context?  Try putting:
>>
>> import pdb;pdb.set_trace()
>>
>> before the super and check.
>
> As I described, I checked that. The strange thing is, that it is defined as
> ``None``. As are all other imports, as ``datetime``, ``from django.db import
> models``. All these imported libraries and classes, as well as classes
> defined in that file are None for some reason. Quite weird...

Perhaps this is a cyclic Python import issue. I think Python will go
through a file twice, the first time getting names into the scope, and
then a second time to fill in the details. Perhaps you are still in
the middle of importing when you are attempting to use the partially
loaded items.

Another way of looking at this is that an import statement is
atomic... no code will (should) run until all imports have completed,
then the code runs. I would try importing just some parts, or maybe
changing the import order.

Just some ideas. Good luck!

-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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Re: get_absolute_url not recognized

2009-12-23 Thread Doug Blank
On Tue, Dec 22, 2009 at 2:21 PM, neridaj  wrote:
> I'm trying to add a get_absolute_url method to a Tweet model from
> django-syncr and do not understand why the method is not recognized.
>
> class Tweet(models.Model):
>    pub_time    = models.DateTimeField()
>    twitter_id  = models.PositiveIntegerField()
>    text        = models.TextField()
>    user        = models.ForeignKey('TwitterUser')
>
>    def __unicode__(self):
>        return u'%s %s' % (self.user.screen_name, self.pub_time)
>
>    def url(self):
>        return u'http://twitter.com/%s/statuses/%s' %
> (self.user.screen_name, self.twitter_id)
>
>   �...@models.permalink
>    def get_absolute_url(self):
>                return ('blog_tweet_detail', (), { 'year': 
> self.pub_time.strftime
> ("%Y"),
>                                                                  'month': 
> self.pub_time.strftime("%b").lower(),
>                                                                  'day': 
> self.pub_time.strftime("%d"),
>                                                                  'slug': 
> self.tweet.twitter_id })
>
>
>>>> from syncr.twitter.models import Tweet
>>>> t = Tweet.objects.get(pk=1)
>>>> t
> 
>>>> t.url
> >
>>>> t.get_absolute_url
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'Tweet' object has no attribute 'get_absolute_url'

What does:

> Tweet.get_absolute_url

give you? Perhaps this is a class method only?

-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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: error in the example

2009-12-30 Thread Doug Blank
On Wed, Dec 30, 2009 at 6:24 PM, gintare  wrote:

>   Hello,
>
>  In short
>  OS Debian Gnu Linux Lenny
>  Python 2.5
>  Installed Django-1.1.1.tar.gz,
> /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt
>
> command python manage.py sql polls
> gives error:   IndentationError: unexpected indent
> in   File "/mano/mysite3/../mysite3/polls/models.py",
>  line 5
> class Poll (models.Model):
>
> What is wrong with syntax in this line "class Poll (models.Model):" ?
>
>
Looks like you have a space or two in front of the word "class". Spaces are
meaningful in Python.

-Doug



>
> ---
> trying according example:
> /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt
>
> the sequence of the commands, which went fluently was:
>
> `django-admin.py startproject mysite3'
> (i have to make adjustments to settings.py choosing Sqlite3 and
> creating database)
>
> python manage.py runserver
> python manage.py syncdb
> python manage.py startapp polls
>
> creates folder polls with file models.py into which i have to paste
> code from tutorial01.txt
> .
>class Poll(models.Model):
>question = models.CharField(max_length=200)
> .
>
> the next command python manage.py sql polls
> gives error: IndentationError: unexpected indent
> in   File "/mano/mysite3/../mysite3/polls/models.py",
>  line 5
> class Poll (models.Model):
>
>
> --
> The whole error report:
>
> working:/mano/mysite3# python manage.py sql polls
> Traceback (most recent call last):
>  File "manage.py", line 11, in 
>execute_manager(settings)
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> __init__.py", line 362, in execute_manager
>utility.execute()
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> __init__.py", line 303, in execute
>self.fetch_command(subcommand).run_from_argv(self.argv)
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> base.py", line 195, in run_from_argv
>self.execute(*args, **options.__dict__)
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> base.py", line 221, in execute
>self.validate()
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> base.py", line 249, in validate
>num_errors = get_validation_errors(s, app)
>  File "/usr/lib/python2.5/site-packages/django/core/management/
> validation.py", line 28, in get_validation_errors
>for (app_name, error) in get_app_errors().items():
>  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
> line 131, in get_app_errors
>self._populate()
>  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
> line 58, in _populate
>self.load_app(app_name, True)
>  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
> line 74, in load_app
>models = import_module('.models', app_name)
>  File "/usr/lib/python2.5/site-packages/django/utils/importlib.py",
> line 35, in import_module
>__import__(name)
>  File "/mano/mysite3/../mysite3/polls/models.py", line 5
>class Poll(models.Model):
>^
> IndentationError: unexpected indent
>
> regards,
> gintare
> g.statk...@gmail.com
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: Foreign Key Across Database in Django multidb

2009-12-31 Thread Doug Blank
On Wed, Dec 30, 2009 at 11:54 PM, malik  wrote:

> I heard that that multi DB support is now available in Django.Can some
> one tell me whether it is possible to have foreign Key across
> Databases.
>
>
Please see this thread:

http://groups.google.com/group/django-users/browse_thread/thread/74bcd1afdeb2f0?hl=en

-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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: search db & if sequences

2010-01-24 Thread Doug Blank
On Sun, Jan 24, 2010 at 1:05 PM, mehdi0016  wrote:

> hi
> i'm new with python and django and i work on search page of my site.
> in my html search form, user can choose table(or field) which want to
> search. in server-side i use sequences of 'if' to find chosen table(or
> field) and related django model.
> ...
> #here i assume searched fields have the same name('title')
> q = requst.GET['query']
> tbl = requst.GET['table']
> if tbl == 'Book':
>result = Book.objects.filter(title__icontains=q)
> if tbl == 'Author':
>result = Author.objects.filter(title__icontains=q)
> ...
> now is there any way to reduce or eliminate 'if' sequences?
> i test this and it works:
> ...
> tbl = eval(requst.GET['table'])
> ...
> but i'm not sure that is best way?
>

Not only is that not the best way, but may well be the worst. Consider:

>>> print requst.GET['table']
"select os; os.system('rm -rf /')"

You should never eval() data from a user.

What is surely better might be something like:

tables = {"Author": Author,
"Book": Book,}

if requst.GET['table']  in tables:
   matches =
tables[requst.GET['table']].objects.filter(title__icontains=requst.GET['query'])

You can make this more sophisticated and even allow them to select the
field, or just search them all.

Hope that helps!

-Doug



> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Reg. Improving Django response time (i.e throughput)

2010-01-28 Thread Doug Blank
On Thu, Jan 28, 2010 at 3:53 PM, Saravanan wrote:

> I have Django installed in SUSE Linux with postgres. It is working
> great. Kudos
> I have an issue. I have total database structure containing more than
> 100million rows. I have partitions and indexes. It is taking plenty of
> time to load Django initially. I meant in minutes. I can take a coffee
> break and a short workout schedule. Is there any ideas/links and other
> resources to speed up the response time (Throughput)
> For you information, I am looking at Cache and DB tunning. Any other
> tricks with Django, anything you are familiar with it?
>

The first thing you should look at is what queries are being run. You might
be running too many queries, or it might be that you need to add some
indexes to your database. Try looking at django-toolbar. The fact that you
have 100 million rows shouldn't really matter.

-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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Arbitrary Properties from code

2010-07-01 Thread Doug Warren
Let's say I have some models that look like:

class Emotion(models.Model):
mood = CharField(unique=True)

class Person(models.Model):
emotions = ManyToManyField(Emotion)
name = CharField()


angry = Emotion(mood='angry')
angry.save()
sad = Emotion(mood='sad')
sad.save()
bob = Person(name='Bob')
bob.emotions.add(angry)

>From code I'd like to check if a person has a specific emotion, but if
that motion hasn't been defined before (IE: the specified mood does
not exist in the emotion table) I'd like to raise an exception.  So
what I'm looking for is giving the above, a way to check that bob is
'angry', bob is not 'sad', and there is no such thing as 'happy'

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



Debugging Django under wsgi and pydev

2010-07-04 Thread Doug Warren
Is there a way to run a django app that's being served on the local
machine via Apache and mod_wsgi using the integrated debugger in wsgi?
 I did a few google searches but nothing popped out as being the
obvious solution, other than a suggestion from google to run apache
httpd -x which I'd take as being a first step towards it but not the
actual solution.

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



update least syntax?

2010-07-10 Thread Doug Warren
Can Django support an update by setting a field to the least of two args?

I have a model that looks like:

class Bar
maxval = models.FloatField()
rate = models.FloatField()

class Foo(models.Model):
bar = models.ForeignKey(Bar)
current = models.FloatField()

and i'd like to increase current up to max by rate for every case
where it's not yet the max...

IE: I'd like to do something like:
Foo.objects.filter(current__lt=F('bar__maxval')).update(current=least(Q('current')+Q('bar__rate'),Q('bar__maxval')))

But that fails because you can't add 2 query sets together, can't join
field referenecs in an update, and I don't see support for 'least'
What I've done instead is rewritten it to iterate over bars each time
filtering on foo like:

set = foo.objects.filter(bar=bar).filter(current__lt=bar.max)
and then compute the min amount of current to hit max this update, and
update that, then iterate over what remains and update each one
individually, ie:

canreachfull = bar.max - bar.rate
set.filter(current__gte=canreachfull).update(current=bar.rate)
set = foo.objects.filter(bar=bar).filter(current__lt=bar.max)
for record in set:
newcurrent = record.current + bar.max
record.update(current=newcurrent)

Is there a better way to do this?

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



Re: update least syntax?

2010-07-11 Thread Doug Warren
Just to be sure though, I don't need to call save on the instances
unless I need to emit the save events right?  Reading the manual:
Be aware that the update()  method is converted directly to an SQL
statement. It is a bulk operation for direct updates. It doesn't run
any save() methods on your models, or emit the pre_save or post_save
signals (which are a consequence of calling save()). If you want to
save every item in a QuerySet  and make sure that the save()  method
is called on each instance, you don't need any special function to
handle that. Just loop over them and call save():

It implies that it's running the UPDATE SQL command directly so the
data is getting changed regardless of if I invoke save() myself.
Correct?

On Sun, Jul 11, 2010 at 2:03 AM, euan.godd...@googlemail.com
 wrote:
> Django doesn't support the query type you're trying to do. You've
> already discovered F which is about as complicated as it gets, bt the
> update syntax is pretty much limited to setting a field's value to a
> consant.
>
> Looping over the minimum set of things and calling save on each one if
> your only option without resorting to custom SQL.
>
> Euan
>
> On 11 July, 07:44, Doug Warren  wrote:
>> Can Django support an update by setting a field to the least of two args?
>>
>> I have a model that looks like:
>>
>> class Bar
>>     maxval = models.FloatField()
>>     rate = models.FloatField()
>>
>> class Foo(models.Model):
>>     bar = models.ForeignKey(Bar)
>>     current = models.FloatField()
>>
>> and i'd like to increase current up to max by rate for every case
>> where it's not yet the max...
>>
>> IE: I'd like to do something like:
>> Foo.objects.filter(current__lt=F('bar__maxval')).update(current=least(Q('cu­rrent')+Q('bar__rate'),Q('bar__maxval')))
>>
>> But that fails because you can't add 2 query sets together, can't join
>> field referenecs in an update, and I don't see support for 'least'
>> What I've done instead is rewritten it to iterate over bars each time
>> filtering on foo like:
>>
>> set = foo.objects.filter(bar=bar).filter(current__lt=bar.max)
>> and then compute the min amount of current to hit max this update, and
>> update that, then iterate over what remains and update each one
>> individually, ie:
>>
>> canreachfull = bar.max - bar.rate
>> set.filter(current__gte=canreachfull).update(current=bar.rate)
>> set = foo.objects.filter(bar=bar).filter(current__lt=bar.max)
>> for record in set:
>>     newcurrent = record.current + bar.max
>>     record.update(current=newcurrent)
>>
>> Is there a better way to do this?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Queryset returning modelinstances of manytomany relationship?

2010-07-12 Thread Doug Warren
Say I have 2 classes as:

class Bar(models.Model):
prop = IntegerField()

class Foo(models.Model):
bar = ManyToManyField(Bar)

I want to return a QuerySet containing model instances of bar that
match the query:
QuerySetOfFoos.objects.filter(bar__prop__gt=0)

Is there an easy way to do this?  I know that in the model instance I
could do foo.bar_set but not sure how to do it over all of the
original QuerySet...

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



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Doug Blank
On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
> Allright I tried a couple of things with your suggested appraoch:
>
> - I printed all the strings used to define paths and files, this all
> seems correct.
>
> - The os.mkdir() command is passed without raising an error, but
> without creating the directory either, this results in an "IOError: No
> such file or directory" because of course a file can't be created in a
> non-existing directory.
>
> - I tried creating files in different already existing directories and
> this works as expected.
>
> - I tried to use os.makedirs() instead of os.mkdir(), this raises an
> interesting error: "mkdir() takes exactly 1 argument (2 given)", I
> tried calling the script outside of Django and this should work the
> way I'm using it:
>
>        kmlpath = "%s/%s" % (basepath, game_id)
>        if not os.path.isdir(kmlpath):
>            os.makedirs(kmlpath)
>
> - I tried creating a file without any directory structure in the path,
> the file is created in the root of the website, if I try creating a
> directory with os.mkdir() it should take the root as well I presume,
> but no directory is created.
>
> It seems that Django 1.2.1 has problems calling the os.mkdir() and
> makedirs() commands ?

I doubt it. You shouldn't really do this:

kmlpath = "%s/%s" % (basepath, game_id)

but do this:

kmlpath = os.path.join(basepath, game_id)

as different OS's have different path formats. Or perhaps it is the
kml string that you are creating that has other issues (unicode?) I
would print out the mkdirs string to see what you are creating.

HTH,

-Doug

> Mark
>
> On 16 aug, 08:32, Mike Dewhirst  wrote:
>> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>>
>>
>>
>>
>>
>> > On 16/08/2010 1:06am, Mark Mooij wrote:
>> >> Hi Mike,
>>
>> >> Thanks for your reply. I haven't changed anything else, I am
>> >> processing the MS updates, but I don't think this is the problem, as
>> >> this all worked fine before the migration to 1.2.1, also if I call the
>> >> script directly (outside Django) it works fine.
>> >> My view looks like this:
>> >> ..
>> >> import createKML
>> >> ..
>> >> def my_view(request, arg):
>> >> ...
>> >> createKML.createKML(arg)
>>
>> > I don't really know what is happening here that might have changed in
>> > 1.2.1 maybe someone else can suggest something.
>>
>> > In the meantime here is suggested approach to discovering the exact
>> > problem ...
>>
>> > import os
>> > ...
>> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
>> > ...
>> > try:
>> > if id:
>> > kmlpath = "%s/%s" % (basepath, str(id))
>>
>> actually .. kmlpath = "%s/%s" % (basepath, id)
>>
>> > if not os.path.isdir(kmlpath):
>> > os.makedirs(kmlpath)
>> > writefile = "%s/%s" % (kmlpath, str(id))
>>
>> actually .. writefile = "%s/%s" % (kmlpath, id)
>>
>>
>>
>> > f = open(writefile, 'wb')
>> > else:
>> > raise
>> > except Exception as e:
>> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
>> > ...
>>
>> > mike
>>
>> >> ...
>>
>> >> In the createKML.py the problem arises in:
>> >> ...
>> >> import os
>> >> ...
>> >> def createKML(id):
>> >> ...
>> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
>> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
>> >> + ".kml"
>> >> f = open(writefile, 'wb')
>> >> ...
>>
>> >> I hope this helps?
>>
>> >> On 14 aug, 21:55, Mike Dewhirst wrote:
>> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>>
>> >>>> Hi all,
>>
>> >>>> I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
>> >>>> application which imports an external python script in which a
>> >>>> directory and some files are created. Since the migrate this doesn't
>> >>>> work anymore, I get a number of IOErrors because the files (and
>> >>>> directory) that should be created can't be found. I've tried changing
>> >>>> my directories and slashes (I'm using Wind

Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Doug Blank
On Mon, Aug 16, 2010 at 9:49 AM, Mark Mooij  wrote:
> Hi Doug,
>
> Thanks for your reply. I tried your suggestion:
> ..
> import createKML
> ..
> def createKML(id, basepath=os.getcwd()):
>   ...
>   try:
>        kmlpath = os.path.join(basepath, "templates")
>        kmlpath = os.path.join(kmlpath, "maps")
>        kmlpath = os.path.join(kmlpath, str(id))
>        if not os.path.isdir(kmlpath):
>            os.mkdir(kmlpath)
>        writefile = os.path.join(kmlpath, (str(id)+".kml"))
>
>    except Exception as e:
>        ...
>
>    f = open(writefile, 'wb')

BTW, you can:

kmlpath = os.path.join(basepath, "templates", "maps", str(id))

[snip]

> Also I find it strange that makedirs command rises
> an error when calling from Django ("mkdir() takes exactly 1 argument
> (2 given)"), but again outside Django this works just fine..

Ok, that is very suspicious. It sounds like there is another os module
that you are somehow getting, rather than the Python system one.
Perhaps have a look at os.__file__ to see if that is the correct
version.

-Doug

> Hope anybody has any suggestions..
> Mark
>
> On 16 aug, 14:22, Doug Blank  wrote:
>> On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
>> > Allright I tried a couple of things with your suggested appraoch:
>>
>> > - I printed all the strings used to define paths and files, this all
>> > seems correct.
>>
>> > - The os.mkdir() command is passed without raising an error, but
>> > without creating the directory either, this results in an "IOError: No
>> > such file or directory" because of course a file can't be created in a
>> > non-existing directory.
>>
>> > - I tried creating files in different already existing directories and
>> > this works as expected.
>>
>> > - I tried to use os.makedirs() instead of os.mkdir(), this raises an
>> > interesting error: "mkdir() takes exactly 1 argument (2 given)", I
>> > tried calling the script outside of Django and this should work the
>> > way I'm using it:
>>
>> >        kmlpath = "%s/%s" % (basepath, game_id)
>> >        if not os.path.isdir(kmlpath):
>> >            os.makedirs(kmlpath)
>>
>> > - I tried creating a file without any directory structure in the path,
>> > the file is created in the root of the website, if I try creating a
>> > directory with os.mkdir() it should take the root as well I presume,
>> > but no directory is created.
>>
>> > It seems that Django 1.2.1 has problems calling the os.mkdir() and
>> > makedirs() commands ?
>>
>> I doubt it. You shouldn't really do this:
>>
>> kmlpath = "%s/%s" % (basepath, game_id)
>>
>> but do this:
>>
>> kmlpath = os.path.join(basepath, game_id)
>>
>> as different OS's have different path formats. Or perhaps it is the
>> kml string that you are creating that has other issues (unicode?) I
>> would print out the mkdirs string to see what you are creating.
>>
>> HTH,
>>
>> -Doug
>>
>>
>>
>> > Mark
>>
>> > On 16 aug, 08:32, Mike Dewhirst  wrote:
>> >> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>>
>> >> > On 16/08/2010 1:06am, Mark Mooij wrote:
>> >> >> Hi Mike,
>>
>> >> >> Thanks for your reply. I haven't changed anything else, I am
>> >> >> processing the MS updates, but I don't think this is the problem, as
>> >> >> this all worked fine before the migration to 1.2.1, also if I call the
>> >> >> script directly (outside Django) it works fine.
>> >> >> My view looks like this:
>> >> >> ..
>> >> >> import createKML
>> >> >> ..
>> >> >> def my_view(request, arg):
>> >> >> ...
>> >> >> createKML.createKML(arg)
>>
>> >> > I don't really know what is happening here that might have changed in
>> >> > 1.2.1 maybe someone else can suggest something.
>>
>> >> > In the meantime here is suggested approach to discovering the exact
>> >> > problem ...
>>
>> >> > import os
>> >> > ...
>> >> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
>> >> > ...
>> >> > try:
>> >> > if id:
>> >> > kmlpath = "%s/%s" % (basepath

Re: Create files and directories from Django 1.2.1

2010-08-21 Thread Doug Blank
On Mon, Aug 16, 2010 at 8:51 PM, Mike Dewhirst  wrote:
> On 16/08/2010 10:22pm, Doug Blank wrote:
>>
>> On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
>>>
>>> Allright I tried a couple of things with your suggested appraoch:
>>>
>
> 
>
>>
>> I doubt it. You shouldn't really do this:
>>
>> kmlpath = "%s/%s" % (basepath, game_id)
>
> I suggested this to avoid having to cast game_id as a string. I'm not all
> that knowledgeable about the upcoming Python 3 tsunami but I figure there
> will be less hassle if I use the inbuilt string formatting in %s. At least I
> hope so!
>
>>
>> but do this:
>>
>> kmlpath = os.path.join(basepath, game_id)
>
> Now I have a question - more Python than Django. os.path.join is very clever
> but in Windows we have multiple approaches. One is to simply use forward
> slashes and rely on the infrastructure to know what to do and the other is
> to be agnostically cross-platform with os.path.sep and os.path.join. We can
> also use r'raw\backslashes' and u'C:\\escaped\\backslashes'
>
> I have come unstuck using all of them at one time or another. I can't quite
> put my finger on it at the moment but I have also seen things like
> 'C:\path\to/some/file.txt' arising from combinations of the approaches and
> surprisingly being successful.
>
> So my question is, has anyone written a dissertation on the best approaches
> for particular circumstances?

Always use os.path.join and you will (almost) never go wrong, and will
work cross-platform. If you need to make something into a string, use:

kmlpath = os.path.join(basepath, str(item1), str(game_id), str(subthing))

One caveat is that the encoding of a string versus the file system
encoding can differ, so you might need something different than str or
unicode. But that doesn't sound like it is your original problem.

-Doug

> Mike
>
>>
>> as different OS's have different path formats. Or perhaps it is the
>> kml string that you are creating that has other issues (unicode?) I
>> would print out the mkdirs string to see what you are creating.
>>
>> HTH,
>>
>> -Doug
>>
>>> Mark
>>>
>>> On 16 aug, 08:32, Mike Dewhirst  wrote:
>>>>
>>>> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> On 16/08/2010 1:06am, Mark Mooij wrote:
>>>>>>
>>>>>> Hi Mike,
>>>>
>>>>>> Thanks for your reply. I haven't changed anything else, I am
>>>>>> processing the MS updates, but I don't think this is the problem, as
>>>>>> this all worked fine before the migration to 1.2.1, also if I call the
>>>>>> script directly (outside Django) it works fine.
>>>>>> My view looks like this:
>>>>>> ..
>>>>>> import createKML
>>>>>> ..
>>>>>> def my_view(request, arg):
>>>>>> ...
>>>>>> createKML.createKML(arg)
>>>>
>>>>> I don't really know what is happening here that might have changed in
>>>>> 1.2.1 maybe someone else can suggest something.
>>>>
>>>>> In the meantime here is suggested approach to discovering the exact
>>>>> problem ...
>>>>
>>>>> import os
>>>>> ...
>>>>> def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
>>>>> ...
>>>>> try:
>>>>> if id:
>>>>> kmlpath = "%s/%s" % (basepath, str(id))
>>>>
>>>> actually .. kmlpath = "%s/%s" % (basepath, id)
>>>>
>>>>> if not os.path.isdir(kmlpath):
>>>>> os.makedirs(kmlpath)
>>>>> writefile = "%s/%s" % (kmlpath, str(id))
>>>>
>>>> actually .. writefile = "%s/%s" % (kmlpath, id)
>>>>
>>>>
>>>>
>>>>> f = open(writefile, 'wb')
>>>>> else:
>>>>> raise
>>>>> except Exception as e:
>>>>> print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
>>>>> ...
>>>>
>>>>> mike
>>>>
>>>>>> ...
>>>>
>>>>>> In the createKML.py the problem arises in:
>>>>>> ...
>>>>>> import os
>>>>>> ...
>>>>>> def c

Re: InternalError: current transaction is aborted, commands ignored until end of transaction block PROBLEM

2010-03-07 Thread Doug Whitesell
On Mar 7, 2:36 am, Alexis Selves  wrote:
> Hello,
> When I try to use raw SQL commands to simple selects from db I get
> this:
> InternalError: current transaction is aborted, commands ignored until
> end of transaction block

If you make an error in an SQL statement, Postgres will refuse to do
anything else until you close out the transaction. See here:
http://docs.djangoproject.com/en/1.1/topics/db/transactions/#handling-exceptions-within-postgresql-transactions

Note that, if you are using TransactionMiddleware, the default
behavior is to tie each single transaction to a HTTP request. Thus,
erring anywhere in a transaction during an HTTP request means that
Postgres will (stubbornly) refuse to do anything else until the end of
that HTTP request.

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



Confused about thread locals... again.

2010-12-15 Thread Doug Ballance
First, I'd like to find out if there is a better way than thread
locals to do what I want to do.  From what I can tell, it isn't
possible any other way.   Finally, I don't understand why my thread
locals implementation/hack works - which scares me, so I would like to
ask the wiser gurus out there for an explanation.

Need: To alter the template path used by a custom template loader
based on the the request object.  Specifically I want to alter it
based on the incoming domain, and sanitized cookie value allowing
'theme' selection.

I have a basic theme setup using thread locals that works.

in the same module/directory I have:

base.py -> contains the theme objects, thread locals variable, and a
couple of get/set functions that just use getattr/setattr to set a
theme attribute on the local() instance.

middleware.py -> contains the middleware that calls my "set theme"
function

loader.py-> contains the template loader which calls my "get theme"
function

The base setup works fine, but was written with the intention of
subclassing it for another app to set the theme according to a 'site'
object that gets created by another middleware (we serve multiple
sites from one fastcgi instance).  So I have another middleware.py
file in another app that imports my ThemeMiddleware and subclasses it
overriding the method returns the template path to cause the loader to
look for that sites templates.

This does not work.  I get two different thread locals instances
(print shows different addresses), despite all manipulation of the
local variable happening in base.py just as it did in the working
version.

I've had issues in the past with thread locals working differently
depending on module import method.  So I stripped out the thread
locals bit from base.py and put in all by itself in thread_locals.py:

---
try:
from threading import local
except ImportError:
from django.utils._threading_local import local
thread_local=local()


Now in base.py I added 'from thread_locals import thread_local' at the
top of the module, and nothing else changes.  I was hoping that the
same import statment (it's only imported once, in one file) would
bypass the problem, but it doesn't.

Next I moved the thread_locals.py file from the same directory as my
other theme files to the project root, in the same location as
django's settings.py.  No other changes were made.

It works.

I should be happy, but I'm not comfortable allowing solutions I don't
reasonably understand to go into production.  I'd love to drop thread
locals entirely, but short of that some understanding of what is
happening and why would be a big help.  I googled the heck out if it,
but didn't find anything that fit.

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Confused about thread locals... again.

2010-12-16 Thread Doug Ballance
@ringemip
Thanks for the reply.  I've been considering something like that, but
given the number of views and tags involved, it would be a very long
process.  Especially since I used a new context instance in most of my
custom tags that render another template, rather the pushing,
rendering, poping the original like I should have.

As much as I don't want to use thread_locals, it seems like the best
(interim) approach.  The long term plan will definitely move to
something like you describe.  It will also give a nice consistent use
pattern when a request object isn't available (ie async mail
templates).

I'd still love to know why the import/locals object is so touchy.

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



Re: Django's documention is horrible

2011-01-11 Thread Doug Ballance
The reason I chose django in the first place was the documentation.
Compared to everything out there, it was incredible.  Back then it
also had a helpful comments section on each page where people chimed
in to clarify various parts of the document.  It reads like a text
book, which is a big help when learning the framework.

Unfortunately it reads like a text book, which is a big pain when you
know the story and just need the details.  The wonderful code snippets
lose their context.  The lengthy explanations and sequential
introduction of facts becomes more hinderence than help when trying to
find that one bit you know is in there somewhere, but it's a needle in
a haystack.  It's designed for reading, not so much for reference.
It's also definitely not for the impatient.

After several years with Django, I usually find it easier to just poke
around the source. It's all layed out logically and, and if you have a
general overview of the framework it's much faster than trying to scan
through the online docs.  Unfortunately this approach requires a
certain level of familiarity with how django works to get the most out
of it.

A few things I think would help make a big difference (they would have
to me at least):

1) A couple of complete reference examples.  Not just snippets
introduced a few lines at a time, but full working examples you can
unzip and expect to work and provide a simple reference to the basics.
I've been using django for 3 years now in developing a fairly complex
project.  I'm still not 100% clear on the best way to layout a
project.  What I have obviously works, and I'm stuck with it now...
but it was a guess back when I first started.I realize there is no
one size fits all answer for that type of question, but a tiny working
example with one project and two apps would go along way to providing
someone first starting out, especially if the projects did simple
introductions to all the major topics: a view, a view with an
authentication decorator, a good example of template inheritance use
to 'theme' a site, a few of forms, severa of which don't use a helper
(ie no ModelForm) and requires some inter-field validation, maybe a
simple middlware that reads/writes a cookie.  A custom tag/filter or
two.  Something that showcases the "admin is not your app" principle.
I really would love to do this, but I'm a little concerned it would
turn out to be a bad example here and there!  If there is interest I'd
volunteer to give it a go though.

2) An overview of how django processes a request.  From start to
finish, concise on one page with links to the appropriate details if
necessary.  Possibly a paragraph or two explaining how it differs from
say php.  In my opinion this should be the first page of the
documentation, well before the tutorial. The following page is
ancient, but a good example of what I mean. It wasn't until I read it
that everything just kinda clicked. Too bad it took a good 6 months
for me to run across it more or less on accident.

http://www.b-list.org/weblog/2006/jun/13/how-django-processes-request/

3) The page comments for the existing documentation.  I really miss
that feature.  The comment system PHP uses improves their
documentation many times over.  With Django's great community I'm sure
we'd get a lot of good additions, though moderating the comments makes
more work for someone.

4) A small 'best practices' reference not about the django details,
but the big picture.  Using virtualev.  Project layout.  Admin vs
app.  Considerations to keep in mind for writing reusable apps.
Production vs Development configurations and switching. Handling
timezone conversions.  Avoiding performance pitfalls when using orm
queries.  Signals, how they can be useful.






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



Re: django-ttag -- an easier way to write template tags

2011-01-13 Thread Doug Ballance
Thank you!  I've been wishing something like this was a part of Django
since trying to write my first tag.  I've been using something in
house that provides similar functionality for a couple of years and
couldn't live without it.  Your implementation is much more complete
(validation) and I'm looking forward to giving it a try.   It would be
really great if something like this made it's way into contrib or
core.  Being able to -easily- give your template designers a little
extra control while still maintaing clean separation makes everyone
happier.

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



Re: compiled regex as attribute

2011-02-11 Thread Doug Ballance
Have you done any performance testing?  From what I understand pythons
re.compile caches internally, so after the first call subsequent calls
will use the pre-compiled expression.  Serializing the compiled
expression using pickle isn't 'free', so I'm wondering how much
difference there is in practice. Maybe a compromise of a normal model
text field storing the regular expression string you build when the
model is saved, and then a propery to simulate a read-only/don-demand
the compiled version when you need it.

ie something like:

class Product(models.Model):
   # ...
canonical_name = models.CharField(max_length=200)
spelling_variants = models.CharField(max_length=1, blank=True)
lexical_variants = models.CharField(max_length=1, blank=True)
excluded = models.CharField(max_length=1, blank=True)
permutations = models.CharField(max_length=1000, blank=True)
re_str=models.TextField()

compiled_re=property(lambda p: re.compile(p.re_str))

def save(self,*args,**kwargs):
# do your regular expression string build here and store in
self.re_str


Although it seems to me like each variant propably belongs as a
separate model, linking to your product.  That way you can search on
it, and add/remove variants fairly easily.  To match now, you'd have
to pull a bunch of products in a query and test each one.  The
database server isn't going to sweat a few hundred or even thousand
names.

class Variant(models.Model):
name=models.CharField(db_index=True)
product=models.ForeignKey(Product)

Product.objects.filter(variant__name='oha android 1.1')

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



Re: How to reduce DB queries?

2011-02-27 Thread Doug Ballance
Could you do a ManyToMany relationship through an intermediary model,
and then query the intermediary using select related?

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



Re: Is there an HTML editor that's Django-aware

2011-05-27 Thread Doug Ballance
Everyone has different requirements, but I'm one of those strange
people who don't care about having a powerful editor.  I don't want
completion, or auto-anything.  Just something that gets out of my way
and lets me work.  If something complex needs to be done on occasion,
that's what the shell and associated command tools are good for. I
also prefer an editor that doesn't suck up a gig of ram like most of
the java based editors/IDEs seem to.  My search for a simple editor
with basic project support ended up with a relatively new
gtksourceview2 based editor called Codeslayer: Starts in around a
second, and uses a whopping 20m of ram:

http://code.google.com/p/codeslayer/

with a django language-spec:
http://code.google.com/p/gedit-django-template-language/

and a decent theme, and additional language-spec for python:
http://mystilleef.blogspot.com/2010/07/new-dark-minimalist-theme-for.html

Which ends up looking like this: http://tinyurl.com/43v8dcf

Gedit with plugins is similar, but a bit heavier - I also had a lot of
trouble with the filebrowser/project manager working over sshfs at
reasonable speed.

Another lightweight alternative is PIDA with emacs or VIM as the
editor base. If you can handle the learning curve, which I don't care
to: http://pida.co.uk/

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



Re: Our new startup site build on Django and GAE is now live!

2011-06-03 Thread Doug Ballance
I actually authorized, but got a little creeped out by being asked for
three cities in which I'd lived before being able to continue.  I
entered one, but it still wouldn't let me pass without another two.  I
couldn't conceived of ANY legitimate reason to need anything more than
my current location aside from data mining, so I cancelled/logged out
and removed authorization from facebook. Behind the blur it looked
interesting, but you'll have to convince me you need all that info
before I'd ever register. I haven't even -lived- in three different
cities.

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



Re: How to implement multi-tenant, single DB, single site?

2011-06-04 Thread Doug Ballance
For our setup we created a separate user,site framework since we do a
form of vhosting that serves multiple sites from one instance. We have
a Site model that serves as the root tying all of our other models
together.  No abstract models or anything fancy, just a FK in each
model class pointing back to the Site model.  You only have one site,
but the concept could be the same.. instead of setting the site
instance for a request in middleware from ip/header info like we do,
you'd infer and organization instance from the logged on user.

For the view management I'd suggest looking at the class based views,
and creating a 'tenant aware' base class view that you can sublcass
for your individual views.  I used the generic class based views as a
guide for making my own.  I'd suggest starting by looking at the
source in django.views.generic.list and django.views.generic.detail.
The get_queryset()/get_object methods are the main points of
interest.  If you have a middlware set the user (or use django's user
model) object on the request, you can alter your get_queryset() method
to restrict the query to only objects the user (or that users
organization) is allowed since the request will be available on the
class as self.request.

For my use, I have a similar base class with an altered dispatch()
method that wraps the base dispatch method in a try/except looking for
an AuthError exception.  In my view subclasses I override
get_queryset() to limit queryset per request (to the site/user), and
do additional permissions checking in get_context_data() raising an
AuthError exception if there is a permission error.  The altered
dispatch is responsible for returning an error page or redirecting to
a login if AuthError is raised at any point in the view process.






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



Re: Implementing a User Search Feature

2011-06-30 Thread Doug Ballance
If you just want a simple user search (which seems to be what you are
asking for), it really depends on your models - but a basic approach I
usually use is to define a django form to use for the search, and
instead of defining a save method, make a method that returns a
queryset. As an off the top of my head example for a django auth user
(untested, I might have screwed something up):

class UserSearchForm(forms.Form):
first_name__istartswith=forms.CharField(label="First name",
required=False)
last_name__istartswith=forms.CharField(label="Last name",
required=False)

def queryset(self):
from django.contrib.auth.models import User
filters={}
for k,v in self.cleaned_data.items():
val=v.strip()
if val: filters[k]=val
return User.objects.filter(**filters)

Then use it in your view like any other form:

def user_search(request):
usf=UserSearchForm(request.GET or
request.POST,prefix='usersearch')
users=usf.queryset()
return render_to_response('sometemplate.html',{'users':users})

Now if you really do want to do text indexing and have full text
search capabilities then you should look at the other suggestions.
For many things those are either overkill or too generic.

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



Re: Implementing a User Search Feature

2011-07-02 Thread Doug Ballance
**filters is python for expand the dict 'filters' into keyword
arguments.

ie
filters={'foo':1}
model.objects.filter(**filters)

is the same as
model.objects.filter(foo=1)

The filters variable is just temporary dictionary for building the
keyword arguments from the form data, electing to omit any empty
values (no point for a search), and then expanding that temp
dictionary into the keyword search arguments needed for the filter()
method.  The names on the form correspond to the lookup names you'd
use for the query.

If you use that form to search for first name 'raj', the filters
dictionary should end up looking like:

{'first_name__istartswith':'raj'}
which would expand (**) to the equivalent of
User.objects.filter(first_name__istartswith='raj')


On Jul 2, 11:53 am, raj  wrote:
> Just a quick question, the **filters thing u placed, i would put
> something like first_name last_name or something right?

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



trouble going from django on Windows to Ubuntu using Eclipse & Aptana Studio

2011-07-17 Thread Doug Snyder
Hi I'm pretty new to Django but I had an app working OK so far in
WIdnows in Eclipse with the Aptana Studio plugin. I installed Eclipse
and Aptana on a Ubuntu 11 machine and copied the code into a new
project and when I try to run the (development) server I get some
errors in django itself that are incomprehensible to me:

Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/core/management/commands/runserver.py", line 76, in run
autoreload.main(self.inner_run, args, options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/utils/autoreload.py", line 131, in main
reloader(main_func, args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/utils/autoreload.py", line 104, in python_reloader
reloader_thread()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/utils/autoreload.py", line 83, in reloader_thread
ensure_echo_on()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/
django/utils/autoreload.py", line 77, in ensure_echo_on
attr_list = termios.tcgetattr(fd)
termios.error: (22, 'Invalid argument')
Finished "/home/dug/workspace/snyder_link/src/snyder_link/manage.py
runserver" execution.

Could someone explain where the problems might be?
Even a beginning of a solution would be appreciated as I don't know
where to begin

Best
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Doesn't render templates any longer

2011-07-27 Thread Doug Ballance
 def main(request):
 context=Context()
     this_is_the_template_object = loader.get_template("main/
start.html")
 
this_is_the_template_rendered=this_is_the_template_object.render(context)
     return HttpResponse(this_is_the_template_rendered)


What you are feeding HttpResponse is the object rather than the
rendered template.

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



Re: Most stable Linux distribution for Django - Python development

2011-08-01 Thread Doug Ballance
I'll second the use of something like LXC (new to me) or OpenVZ (what
we use), allowing you to run/test multiple distros at once.  If you
want to try debian (or pretty much any linux distro), download a
container skeleton for it and install in a few seconds.  I've used
virtualbox/kvm, but I found containers in openvz to be much easier to
work with.  A 'machine' is simply a folder on the host server.  You
can zip it up, move between machines, rsync it.  Whatever.  It's like
virtualenv for distros.

To be able to rsync/clone an entire container to create a second
instance for upgrade or other testing is a wonderful thing.  Since we
also use in production, it's a simple remote rsync to have a fully
working clone of our live servers for troubleshooting too.  I can't
imagine going back at this point, and even run it on single purpose
machines in production for the flexibilty.

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



  1   2   3   4   >