Re: Admin Ordering

2009-01-15 Thread Scott Moonen
Sanrio, this is a known problem.  See open ticket
http://code.djangoproject.com/ticket/4926

  -- Scott

On Thu, Jan 15, 2009 at 11:21 AM,  wrote:

>
> Hi,
>
> I just found out that you can only use one ordering key in the
> ordering. Is this true? If so, what can I do to have ordering on 2
> keys
> instead? (short of overriding the admin, and writing my own custom
> class)
>
> Thanks,
>
> sanrio
>
>
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: Logout- Back Button

2008-11-06 Thread Scott Moonen
Hi,

This is why many secure web application (e.g., your bank or credit card
company) ask that you close your browser after you logout -- so that no one
else can get to any of your data that may be stored in the browser cache.

If your users are using your application from https:, then this is all you
have to worry about -- ask them to close their browser and the data will be
cleared (browsers should not persist https cached data after exit).  If your
users are using vanilla http, then you should ensure that your application
is sending the appropriate Cache-Control header to force the page not to be
cached.  In any case, you will still need to ask your users to close their
browser after logout.

  -- Scott

On Thu, Nov 6, 2008 at 11:26 AM, jai_python <[EMAIL PROTECTED]> wrote:

>
> Hi, i have created a project named as Asset and application named as
> Management. The problem i am facing is after  i logout form the
> project, if i hit the back button it fails to show the login window. I
> knew that some browsers don't actually hit the server on a "back". So
> can u tel me how to implement "redirect to login page, if i hit back
> button after logout." Its very urgent to implement in my project.
> would be thank full for replies :)
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: DeprecationWarning: Non-ASCII character in models.py

2008-09-30 Thread Scott Moonen
An alternative solution is to replace the pound character with the HTML
entity £.
  -- Scott

On Tue, Sep 30, 2008 at 8:01 AM, Jens <[EMAIL PROTECTED]> wrote:

>
> I got the same message the other day and the solution was to put
> following line at the top (first line, befor everything else) of my
> models.py:
>
> #coding: utf8
>
> worked for me, hope it'll work for you.
>
> Jens
>
> On 30 Sep., 13:07, Nick <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I've recently noticed that I'm getting the following in my Apache
> > error log...
> >
> > DeprecationWarning: Non-ASCII character '\xc2' in file /var/www/django/
> > newsite/web/models.py on line 101, but no encoding declared; seehttp://
> www.python.org/peps/pep-0263.htmlfor details
> >
> > Line 101 in my models.py file contains...
> >
> > price_per_week = models.CharField(max_length=100, blank=True,
> > help_text="Calculate average price per week.  Include
> > £ prefix.Example: \"£150\",
> > \"£300-£320\", \"£100+\"")
> >
> > I'm guessing it's something to do with the help_text, specifically the
> > £ symbol.
> >
> > Can anybody shed some light on how I can fix this, presumably I need
> > to declare an encoding, or there is an encoding mismatch going on
> > somewhere?
> >
> > Thanks,
> > Nick
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: Recursively rendering in template

2008-09-24 Thread Scott Moonen
Haven't tried it, but off the top of my head it seems like you could
accomplish this by combining 'with' (to temporarily rename the child) and
'include':

*app/node.html:*
{{ node.name }} . . .

  {% for child in node.children %}
{% with child as node %}{% include 'app/node.html' %}{% endwith %}
  {% endfor %}


   -- Scott

On Wed, Sep 24, 2008 at 2:17 PM, David Koblas <[EMAIL PROTECTED]> wrote:

>
> I'm not sure if this is possible to do without writing a templatetag
> (ok, that's my theory).
>
> Basic idea is that I have a tree structure that I want to render into a
> template, the one example that I found pre-rendered a template into a
> template variable and then rendered it into the page.
>
> What I would really like to be able to do is something akin to:
>...html...
>{% render node %}
>
>{% render children %}
>
>html...
>
> Any quick answers, before I spend the afternoon figuring out if a
> template tag is going to work?
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Multiple instances using mod_python

2008-09-24 Thread Scott Moonen
FYI because there was some wildcarding going on, I think my ServerNames were
actually duplicate in the two VirtualHost definitions (unqualified main
domain name) and I was accomplishing any differentiation using ServerAlias.
According to the mod_python docs <
http://www.modpython.org/live/current/doc-html/pyapi-interps.html>, this
must have caused my instances to share an interpreter, probably resulting in
some unfortunate collisions on key modules (like the settings file, which
had the same path in both handlers).  So I added the PythonInterpreter
directive as suggested by mod_python and as indicated in the Django docs <
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/>.  Haven't
had much opportunity to test, but I expect this will do the trick.

Just wanted to close the loop here on the list in case someone stumbles
across this in the future,

  -- Scott

On Wed, Sep 24, 2008 at 12:11 PM, David Durham, Jr. <
[EMAIL PROTECTED]> wrote:

>
> > I see on this thread
> > <
> http://groups.google.com/group/django-users/browse_thread/thread/4f0cb183eb5b43cd/7be0fa3681b73220?lnk=raot
> >
> > from last year that there is suspicion that Apache can at times misdirect
> > mod_python requests to the wrong mod_python instance.
>
> You could try mod_wsgi.
>
> -Dave
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Multiple instances using mod_python

2008-09-24 Thread Scott Moonen
I'm running a single instance of Apache to serve two IP addresses.  One IP
address has specific hostnames assigned in several VirtualHosts, and a
Location statement for certain hostnames to be handled by a mod_python
instance running a Django application.  The other IP address has a
wildcarded ServerAlias, and DNS is setup so that any hostname not
specifically assigned to the first IP address is directed to this second IP
address.  For this second IP address I have a VirtualHost that also uses a
mod_python instance running a different Django application.

I see on this thread <
http://groups.google.com/group/django-users/browse_thread/thread/4f0cb183eb5b43cd/7be0fa3681b73220?lnk=raot>
from last year that there is suspicion that Apache can at times misdirect
mod_python requests to the wrong mod_python instance.  And this is what I'm
experiencing from time to time.  It's a bit strange, though: 1) normal file
content on these same virtual hosts outside of my mod_python 
statement seems to load fine, so Apache seems to be confused only when
directing requests to mod_python; 2) this is intermittent, as several
requests in a row may go to the wrong handler while a subsequent request may
go to the proper handler; 3) I have taken care to force a specific ordering
in my virtual host definitions, but this has not helped, although I kind of
expected that given that the problem is intermittent; and 4) the wildcarded
virtual host is in fact the only virtual host on my second IP address, and I
have no other VirtualHosts for that IP address, so the fact that Apache
seems to be misdirecting the mod_python handler to virtual hosts for an
entirely different IP address is pretty disconcerting.

I'm running Apache 2.2.3, mod_python 3.3.1, and the latest Django SVN.
Because filesystem content loads fine, and because this problem is polluting
VirtualHosts that don't even share the same IP address, it seems intuitive
that the problem must be some weakness in Apache's internal scoping of
Location statements to the VirtualHosts that they appear in.

Is anyone else experiencing this problem?  Is anyone aware of any fixes?
Based on my guess that the problem is Apache's internal scoping of Location
directives, I'm tempted to switch from mod_python to mod_fastcgi.  But I'd
rather stick with the recommended mod_python deployment method if there's a
known way of getting things working,

  -- Scott

-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: New Comments: Bad Magic Number Error

2008-09-10 Thread Scott Moonen
Hi Dave.  I'm not sure how the .pyc file got corrupted, but from the error
it sounds like it did.  Perhaps you're running with a mix of Python
versions?  But I'd remove the .pyc file referenced by the error and try
again.
  -- Scott

On Wed, Sep 10, 2008 at 1:46 PM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:

>
> I have looked everywhere. Tickets, here and in the source. I am
> getting a strange Bad Magic Number error when I first install
> contrib.comments. The traceback is below. Any ideas?
>
> Environment:
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/admin/page/content/
> Django Version: 1.0-final-SVN-8983
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'django.contrib.comments',
>  'django.contrib.formtools',
>  'django.contrib.humanize',
>  'django.contrib.markup',
>  'django.contrib.redirects',
>  'django.contrib.sitemaps',
>  'django.contrib.syndication',
>  'bluechannel.media',
>  'bluechannel.layout',
>  'bluechannel.accounts',
>  'bluechannel.page',
>  'bluechannel.gathering',
>  'bluechannel.blog',
>  'bluechannel.demo',
>  'bluechannel.utils',
>  'tagging',
>  'template_utils',
>  'comment_utils']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.middleware.doc.XViewMiddleware')
>
>
> Traceback:
> File "/opt/local/lib/python2.5/site-packages/django/core/handlers/
> base.py" in get_response
>  86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/opt/local/lib/python2.5/site-packages/django/contrib/admin/
> sites.py" in root
>  158. return self.model_page(request, *url.split('/',
> 2))
> File "/opt/local/lib/python2.5/site-packages/django/views/decorators/
> cache.py" in _wrapped_view_func
>  44. response = view_func(request, *args, **kwargs)
> File "/opt/local/lib/python2.5/site-packages/django/contrib/admin/
> sites.py" in model_page
>  177. return admin_obj(request, rest_of_url)
> File "/opt/local/lib/python2.5/site-packages/django/contrib/admin/
> options.py" in __call__
>  189. return self.changelist_view(request)
> File "/opt/local/lib/python2.5/site-packages/django/contrib/admin/
> options.py" in changelist_view
>  662. ], context,
> context_instance=template.RequestContext(request))
> File "/opt/local/lib/python2.5/site-packages/django/shortcuts/
> __init__.py" in render_to_response
>  18. return HttpResponse(loader.render_to_string(*args,
> **kwargs), **httpresponse_kwargs)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> loader.py" in render_to_string
>  107. return t.render(context_instance)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  176. return self.nodelist.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  768. bits.append(self.render_node(node, context))
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render_node
>  781. return node.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> loader_tags.py" in render
>  97. return compiled_parent.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  176. return self.nodelist.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  768. bits.append(self.render_node(node, context))
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render_node
>  781. return node.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> loader_tags.py" in render
>  97. return compiled_parent.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  176. return self.nodelist.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  768. bits.append(self.render_node(node, context))
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render_node
>  781. return node.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> defaulttags.py" in render
>  245. return self.nodelist_true.render(context)
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render
>  768. bits.append(self.render_node(node, context))
> File "/opt/local/lib/python2.5/site-packages/django/template/
> __init__.py" in render_node
>  781. return node.render(context)
> File "/opt/local/lib/python2.5/site-

Re: Link to CSS and JS files other than in base.html

2008-09-08 Thread Scott Moonen
Hi,
What I do is put an empty {% block extrahead %}{% endblock %} and {% block
extrastyle %}{% endblock %} in my base.html.  Then in any specific template
that extends base or base_site, I can fill in those blocks with {% block
extrastyle %}{% endblock %}.  Otherwise it will be
served up blank.

Hope that helps,

  -- Scott

On Mon, Sep 8, 2008 at 6:47 AM, Bobo <[EMAIL PROTECTED]> wrote:

>
> Hi everyone,
>
> I've a question about loading CSS and JS files. The normal command for
> doing so is:
>
> 
> 

Re: last security fix

2008-09-04 Thread Scott Moonen
Pavel, you should get in touch with the Debian package maintainers for
Django.  You can find their contact information here:
http://packages.debian.org/etch/python-django.
  -- Scott

On Thu, Sep 4, 2008 at 3:29 PM, pavel srb <[EMAIL PROTECTED]> wrote:

>
> hi all
> please, due to http://www.djangoproject.com/weblog/2008/sep/02/security/
> i would like to know, when there will be security patch for  debian
> etch version
>
> thank you
> pavel srb
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Forms problem?

2008-08-28 Thread Scott Moonen
Greg, it looks to me like you are storing a date value into a datetime
field.  Consider the error:

 File "/home/clemsoncrew/site-packages/django/forms/widgets.py", line 662,
> in decompress
>   return [value.date(), value.time().replace(microsecond=0)]
>
> AttributeError: 'datetime.date' object has no attribute 'date'
>

The Django code is trying to peel away the date and time values from the
value in the form field.  But evidently the form field contains a
datetime.date, whereas Django is expecting a datetime.datetime.  Does that
make sense?  Perhaps you are passing in something like
"datetime.date.today()" where you should be passing in something like
"datetime.datetime.now()".  Or else maybe your field really should be a date
field instead of a datetime field?

  -- Scott

On Thu, Aug 28, 2008 at 11:35 AM, Greg Taylor <[EMAIL PROTECTED]>wrote:

>
> Thanks for the tip. I replaced all of my from datetime import datetime
> istances, but it looks like this is still happening. The problem only
> manifested itself when I updated to the latest trunk. I was previously
> running a few revisions earlier than the signals refactoring. If you
> have any other ideas, I'm all ears, this is a bit of a showstopper for
> me.
>
> Thanks!
> Greg
>
> On Aug 28, 10:31 am, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
> > On Aug 28, 3:01 pm, Greg Taylor <[EMAIL PROTECTED]> wrote:
> >
> > > I'm getting the following error on some of my models with
> > > DateTimeFields. Any ideas?
> >
> > > Traceback (most recent call last):
> >
> > ... snip. ...
> >
> > >  File "/home/clemsoncrew/site-packages/django/forms/widgets.py", line
> > > 662, in decompress
> > >return [value.date(), value.time().replace(microsecond=0)]
> >
> > > AttributeError: 'datetime.date' object has no attribute 'date'
> >
> > This probably means that somewhere in your code you've done "from
> > datetime import datetime" rather than just "import datetime".
> > Annoyingly and confusingly, both the module and one of its classes are
> > called datetime. The *module* 'datetime' does have an attribute called
> > 'date', but the *class* 'datetime' does not.
> >
> > Basically, unless you have a very good reason, you should always use
> > "import datetime".
> > --
> > DR.
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: fcgi - Problem using daemonize=true

2008-08-21 Thread Scott Moonen
Paddy, I can't remember all the details of my fcgi testing, but I think I
saw the same mysterious behavior when I specified a relative path for the
pid file.  Once I specified an absolute path things seemed to work ok.  I
may be misremembering, or this may not be your problem.  But it's worth a
try,

  -- Scott


On Thu, Aug 21, 2008 at 5:50 AM, Paddy Joy <[EMAIL PROTECTED]> wrote:

>
> I'm not sure what's going on here, can anyone help?
>
>
> When I run the following command:
>
> python manage.py runfcgi daemonize=false method=threaded
> host=127.0.0.1 port=3033 pidfile=django.pid
>
> everything works fine. The file django.pid is created and I can access
> my django app through an apache vhost using FastCGIExternalServer /
> home/user/html/mysite.fcgi -host 127.0.0.1:3033
>
>
> However when I run:
>
> python manage.py runfcgi daemonize=true method=threaded host=127.0.0.1
> port=3033 pidfile=django.pid
>
> nothing happens, no django.pid is created and I can't locate any error
> messages anywhere.
>
> Anyone any ideas?
>
> Paddy
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: does it means we have to user Admin tool?

2008-07-21 Thread Scott Moonen
Hi Eric.  Take a look at Django's generic views (
http://www.djangoproject.com/documentation/generic_views/), especially the
List/Detail generic views and the Create/Update/Delete generic views on that
page.  If these generic views suit your needs then you may be able to get
away with writing only some template code.

  -- Scott

On Mon, Jul 21, 2008 at 5:45 AM, Eric Liu <[EMAIL PROTECTED]> wrote:

> Hi all,
> after I readed the djangobook,I found if I wrote following code and I
> want to get some cool stuff.like auto generate the CRUD logic,I found that I
> have to use the Django Admin tool.I mean if I use Rails Or Grail,it can auto
> generate the code for me (both logic code and page code).but it seems that
> Django didn't provide these feature.I think if I want to some "user_define"
> feature ,and I don't use the Django Admin tool,that means I have to write
> some redundancy,for example every model with same CRUD method.and even if I
> extend the Django Admin template ,and  I want to custom some behavious of
> page logic,it's tough.
>
> Is there some better methods I can use under Django,like Rails or Grails?
>
> Thanks
>
>
>
>
> class Publisher(models.Model):
> name=models.CharField(max_length=30)
> address=models.CharField(max_length=50)
> city=models.CharField(max_length=60)
> state_province=models.CharField(max_length=30)
> country=models.CharField(max_length=50)
> website=models.URLField()
>
> def __str__(self):
> return self.name
> class Meta:
> ordering=['name']
> class Admin:
> pass
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Nested for loops in template

2008-07-18 Thread Scott Moonen
Brian, without knowing exactly how your models are configured, you can do
something like this:

{{ p.comment_set.count }}

If you use it in more than one place (e.g., as {% if p.comment_set.count %}
... {{ p.comment_set.count }} ...), you will want to optimize things so that
the SQL "COUNT()" query is executed only once:

{% with p.comment_set.count as comment_count %}
  {% if comment_count %} . . . {{ comment_count }} . . . {% endif %}
{% endwith %}

If you have any trouble getting this working, please let us have a look at
your entry and comment models (use dpaste.com) and we can help you figure
out exactly what to write.

  -- Scott

On Fri, Jul 18, 2008 at 11:47 AM, brianmac44 <[EMAIL PROTECTED]> wrote:

>
> I have two tables, one is entries and the other is comments.
>
> In the template I would like display how many comments for each entry
> and some other entry data.
> So far I have...
>
> view:
> entries_list = entries.objects.filter( ...)
>
> template:
> {% for p in object_list %}
> 
>
>{{ p.name }}
>
> 
>...
>
> 
> {% endfor %}
>
> How is this done? Should I use select_related in the view?
> Thanks in advance.
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Nested for loops in template

2008-07-18 Thread Scott Moonen
Brian, I think the solution is to add a GenericRelation to your entries
model; see
http://www.djangoproject.com/documentation/contenttypes/#reverse-generic-relationsfor
an explanation.  I think that after doing this you'll be able to
access
p.comments.count (assuming that the generic relation is named "comments").
I haven't used the contenttypes framework yet, but from the looks of it I
believe that will work.

  -- Scott

On Fri, Jul 18, 2008 at 12:21 PM, brianmac44 <[EMAIL PROTECTED]> wrote:

>
> Hi Scott,
> Thanks for your help, but I'm still having trouble.
> I using django-threadedcomments
> http://code.google.com/p/django-threadedcomments/
> so its a little confusing.
>
> Here are my models
> http://dpaste.com/65848/
>
> -Brian
>
> On Jul 18, 12:01 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > Brian, without knowing exactly how your models are configured, you can do
> > something like this:
> >
> > {{ p.comment_set.count }}
> >
> > If you use it in more than one place (e.g., as {% if p.comment_set.count
> %}
> > ... {{ p.comment_set.count }} ...), you will want to optimize things so
> that
> > the SQL "COUNT()" query is executed only once:
> >
> > {% with p.comment_set.count as comment_count %}
> >   {% if comment_count %} . . . {{ comment_count }} . . . {% endif %}
> > {% endwith %}
> >
> > If you have any trouble getting this working, please let us have a look
> at
> > your entry and comment models (use dpaste.com) and we can help you
> figure
> > out exactly what to write.
> >
> >   -- Scott
> >
> >
> >
> > On Fri, Jul 18, 2008 at 11:47 AM, brianmac44 <[EMAIL PROTECTED]> wrote:
> >
> > > I have two tables, one is entries and the other is comments.
> >
> > > In the template I would like display how many comments for each entry
> > > and some other entry data.
> > > So far I have...
> >
> > > view:
> > > entries_list = entries.objects.filter( ...)
> >
> > > template:
> > > {% for p in object_list %}
> > > 
> > >
> > >{{ p.name }}
> > >
> > > 
> > >...
> > >
> > > 
> > > {% endfor %}
> >
> > > How is this done? Should I use select_related in the view?
> > > Thanks in advance.
> >
> > --http://scott.andstuff.org/|http://truthadorned.org/<http://scott.andstuff.org/%7Chttp://truthadorned.org/>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Heavy database query (max 32 tables problem)

2008-07-18 Thread Scott Moonen
Norman, unfortunately I think he's asking for the mutual intersection of the
users' courses, not the union.

  -- Scott

On Fri, Jul 18, 2008 at 11:49 AM, Norman Harman <[EMAIL PROTECTED]>
wrote:

>
> Deniz Dogan wrote:
> > Hey.
> >
> > I have a model Course and then I have django.contrib.auth.models.User.
> > Users and courses are related through M2M, so a user can register for
> > many courses and a course can register multiple users. Now, given a
> > potentially very long list of users, I want to retrieve all the
> > courses for which all of those users have registered. Currently I have
> > implemented it in this manner:
> >
> > courses = Course.objects.all()
> > for user in users:
> >   courses = courses.filter(users=user)
> > courses = courses.distinct()
> >
> > As you might expect, I get the "maximum 32 tables in a join" error
> > when having a very long list of users. How would I go about doing what
> > I want here?
>
> http://www.djangoproject.com/documentation/db-api/#in
>
> user_ids = [u.id for u in users]
> # or user_ids = User.objects.values_list("id", flat=true)
> courses = Course.objects.filter(users__id__in=user_ids)
>
> I've used 'in' with a many hundreds ids.  Have no idea how performant it
> is compared to other solutions.
>
>
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> ___
> You've got fun!  Check out Austin360.com for all the entertainment
> info you need to live it up in the big city!
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Modulo of 4 not working right

2008-07-16 Thread Scott Moonen
Joshua,

For the simple fix, I think you should remove the word "not" from your while
condition.

The better fix is to do the math all in one step:

amountofblanks += (4 - (len(templist) + amountofblanks) % 4) % 4

  -- Scott

On Wed, Jul 16, 2008 at 10:30 AM, joshuajonah <[EMAIL PROTECTED]> wrote:

>
> I have a form model that is generating a dynamic number of fields. It
> is using a modulo conditional to see if the amount of fields if
> divisible by 4 (4 column layout). If it doesn't divide, it adds
> another field and then tries again.
>
> This is not working, it is returning field lists that are 30 (/4=7.5).
> I need this function to return only int numbers, no floats.
>
> Any idea how i can rewrite this?
>
> http://dpaste.com/65357/
>
> Here's the page I'm using it on, you can see the ones that don't work
> right, it adds fields that don't fit into the layout:
>
> http://www.hftvnetwork.com/ProIn/
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: templates: additional forloop variable?

2008-07-14 Thread Scott Moonen
(Tim - thanks for the suggestion.)

Russ,

I'm considering adding a forloop.previous (or somesuch) variable to the
>> supplemental variables produced by the for tag.  If forloop.first is true,
>> this value would always be None, but otherwise it would reference the
>> actual
>> loop item from the prior iteration.
>>
>
> I can't help but get the feeling that there is another way to skin
> your cat. However, without knowing exactly what you're trying to do,
> its difficult to tell for certain.
>

Here's my use case: think tags with tag bundles.  So I have a list of tags
for an object that are like ("AGroup:Tag1", "AGroup:Tag2", "FluxCapacitor",
"ZGroup:Tag1", "ZGroup:Tag2").  At the moment I'm storing tags like this, as
"bundle:tagname" or "tagname".  For display purposes I order them by that
string, and format bundles within a , but individual tags as-is.  When
<% ifchanged tag.get_bundle %> (get_bundle is an instance method), I want to
determine whether I need to emit a , so I need to access the previous
tag in the list to determine if get_bundle returns an empty string.

As I write this, "forloop.previous" aside, it occurs to me that an alternate
approach might be for me to provide the unbundled and bundled tags to my
template in separate lists and display the unbundled tags all together
rather than interspersed.  Come to think of it, that might actually display
more attractively -- it could be rather ugly to have tags and bundles
interspersed.

Thank you for serving as my
CardboardProgrammer<http://c2.com/cgi/wiki?CardboardProgrammer>for the
day. :)

  -- Scott

On Mon, Jul 14, 2008 at 7:53 AM, Russell Keith-Magee <[EMAIL PROTECTED]>
wrote:

>
> On Mon, Jul 14, 2008 at 7:46 AM, Scott Moonen <[EMAIL PROTECTED]>
> wrote:
> > I'm considering adding a forloop.previous (or somesuch) variable to the
> > supplemental variables produced by the for tag.  If forloop.first is
> true,
> > this value would always be None, but otherwise it would reference the
> actual
> > loop item from the prior iteration.
>
> I can't help but get the feeling that there is another way to skin
> your cat. However, without knowing exactly what you're trying to do,
> its difficult to tell for certain.
>
> > Is there sufficient interest in this that I should consider going the
> extra
> > mile by opening a ticket and submitting a patch?
>
> I can't vouch for the community as a whole, but as fair warning: the
> core developers are preoccupied with delivering v1.0 at the moment, so
> you may find that suggestions about improvements that aren't on the
> schedule for v1.0 will probably get ignored for a little while
>
> > Or (please excuse my
> > ignorance!) is opening a ticket actually the preferred way to gauge the
> > interest level?
>
> Generally, doing both is a good idea. The ticket tracks the idea
> itself - if nobody is interested, we can close the ticket, and if
> anyone else has the same idea later on, we can point them at the
> ticket. The mailing list enables you to establish who is interested in
> the idea, and nail down the little details.
>
> Yours,
> Russ Magee %-)
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



templates: additional forloop variable?

2008-07-13 Thread Scott Moonen
Within a Django template, sometimes I find myself wishing that I had access
to the loop item from the previous iteration of a loop.

Usually the ifchanged tag is good enough for my purposes, but occasionally
if some attribute of the loop item has changed I need to do further
examination of the previous item to determine what sort of wrap-up (e.g.,
tag closing) needs to be done.

I'm considering adding a forloop.previous (or somesuch) variable to the
supplemental variables produced by the for tag.  If forloop.first is true,
this value would always be None, but otherwise it would reference the actual
loop item from the prior iteration.

Is there sufficient interest in this that I should consider going the extra
mile by opening a ticket and submitting a patch?  Or (please excuse my
ignorance!) is opening a ticket actually the preferred way to gauge the
interest level?

  -- Scott

-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: postgres schema support

2008-07-11 Thread Scott Moonen
Aah, I think you'll need to create the schema yourself.

  -- Scott

On Fri, Jul 11, 2008 at 10:35 AM, Jon Brisbin <[EMAIL PROTECTED]> wrote:

> Will this actually create the schema, though? Or will that have to be done
> manually, with Django managing the tables inside the schemas I create
> myself?
>
> Thanks!
>
> Jon Brisibn
> http://jbrisbin.com
>
> On Jul 11, 2008, at 9:01 AM, Scott Moonen wrote:
>
> Hi Jon.  I believe you can use the Django model meta property db_table to
> specify the schema.  According to ticket 
> #6064<http://code.djangoproject.com/ticket/6064>you need to use somewhat 
> hackneyed syntax at the moment (notice the outer
> single quotes and the explicit inner double quotes):
>
> class MyModel(models.Model) :
>   . . .
>
>   class Meta :
> db_table = '"accounting"."mymodel"'
>
> It looks like ticket #6064 addresses putting schemas into your search order
> for search purposes, but not explicitly specifying schemas for lookup or
> table creation.  Unless the PostgreSQL quote function is made smarter before
> 1.0, it's probably a good idea for you to continue to use this syntax.
>
>
>   -- Scott
>
> On Fri, Jul 11, 2008 at 9:50 AM, Jon Brisbin <[EMAIL PROTECTED]>
> wrote:
>
>>
>> I hardly ever put anything in the Postgres "public" schema except for
>> things I want exposed to all applications and tables within a
>> database. I usually segregate the tables into schemas based on their
>> relationship to one another. With several hundred tables in the
>> database, this gets pretty critical. I noticed Django doesn't have any
>> explicit schema support, but instead uses app prefixes. I realize that
>> some would argue that's functionally equivalent. But not when you're
>> looking at all those tables in pgAdmin.
>>
>> Would it be difficult to add schema support for those databases that
>> support it rather than using the app_table naming methodology? Just
>> create a schema called "app" and then the table named after the model.
>> I guess it's really a personal preference, but I'm used to working
>> with schemas because of the large number of tables in our warehouse.
>> Maybe we're unusual in how heavily we rely on Postgres, but it's a
>> convention that I've grown to prefer over the past several years. It
>> also prevents me from using Django in our mission-critical apps
>> because all our tables are segregated into schemas and we use several
>> tables in different schemas. I don't get the impression that Django is
>> necessarily targeted at the large, enterprise environment, but I would
>> prefer to use Django over how we do it now (JBoss and SQL, of course :).
>>
>> Thanks!
>>
>> Jon Brisibn
>> http://jbrisbin.com
>>
>>
>>
>>
>
>
> --
> http://scott.andstuff.org/ | http://truthadorned.org/
>
>
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: postgres schema support

2008-07-11 Thread Scott Moonen
Hi Jon.  I believe you can use the Django model meta property db_table to
specify the schema.  According to ticket
#6064you need to use
somewhat hackneyed syntax at the moment (notice the outer
single quotes and the explicit inner double quotes):

class MyModel(models.Model) :
  . . .

  class Meta :
db_table = '"accounting"."mymodel"'

It looks like ticket #6064 addresses putting schemas into your search order
for search purposes, but not explicitly specifying schemas for lookup or
table creation.  Unless the PostgreSQL quote function is made smarter before
1.0, it's probably a good idea for you to continue to use this syntax.


  -- Scott

On Fri, Jul 11, 2008 at 9:50 AM, Jon Brisbin <[EMAIL PROTECTED]> wrote:

>
> I hardly ever put anything in the Postgres "public" schema except for
> things I want exposed to all applications and tables within a
> database. I usually segregate the tables into schemas based on their
> relationship to one another. With several hundred tables in the
> database, this gets pretty critical. I noticed Django doesn't have any
> explicit schema support, but instead uses app prefixes. I realize that
> some would argue that's functionally equivalent. But not when you're
> looking at all those tables in pgAdmin.
>
> Would it be difficult to add schema support for those databases that
> support it rather than using the app_table naming methodology? Just
> create a schema called "app" and then the table named after the model.
> I guess it's really a personal preference, but I'm used to working
> with schemas because of the large number of tables in our warehouse.
> Maybe we're unusual in how heavily we rely on Postgres, but it's a
> convention that I've grown to prefer over the past several years. It
> also prevents me from using Django in our mission-critical apps
> because all our tables are segregated into schemas and we use several
> tables in different schemas. I don't get the impression that Django is
> necessarily targeted at the large, enterprise environment, but I would
> prefer to use Django over how we do it now (JBoss and SQL, of course :).
>
> Thanks!
>
> Jon Brisibn
> http://jbrisbin.com
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Alpha Chars in dynamic url?

2008-07-10 Thread Scott Moonen
Luke, this should work.  Here's an example I use:

*urls.py:*
url('^user/(?P\w+)/$', user.view)

*views/user.py:
*def view(request, user_id) :
  user = get_object_or_404(User, username = user_id)

Hope that helps,

  -- Scott

On Thu, Jul 10, 2008 at 1:42 PM, lukeqsee <[EMAIL PROTECTED]> wrote:

>
> Sorry I didn't my last post clear
> what I want is mysite.com/people/ {dynamic url ie. name)/
>
> On Jul 10, 1:34 pm, lukeqsee <[EMAIL PROTECTED]> wrote:
> > Can you use alpha characters in the urls? like mysite.com/people/
> > [name]/
> >
> > Is this possible? Haven't found anything in the documentation relating
> > to it.
> >
> > Thanks,
> > Luke
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: A little help with an idea

2008-07-03 Thread Scott Moonen
Bryan, here's one way that you might approach it:

   1. From a model perspective, you probably want to have a model like
   Account or Person or Blog that corresponds to the first component of the URL
   path.  Then you can have a model like BlogPost or somesuch (maybe other
   models like BlogStaticPage, BlogCalendarEntry) that has a ForeignKey
   relating back to the top-level Blog model
   2. Create a single Django project and give it responsibility for your web
   root.
   3. Now you can have URL dispatching and view methods that consume both
   the first component of the url (/friend1) and also the blog page component
   (e.g., /post-3).
   4. The tricky part is that you'll need some special logic in the view
   method that pulls in the appropriate user-specific template.  There are
   various ways you can approach that; e.g., have paths to the view template
   specified in the Blog model, or perhaps even have the view templates for a
   blog contained directly within the database.

There may be some challenges (esp. #4) with implementing this as a single
Django project, but I think that overall you'll find it a much better
solution than cloning your Django projects.

  -- Scott

On Thu, Jul 3, 2008 at 8:50 AM, bbeaudreault <[EMAIL PROTECTED]> wrote:

>
> Hey Daniel,
>
> Thanks for the reply. ... Duh!  I don't know why I didn't think of
> that.  There are so many foreign aspects of this to me (yes I come
> from a mod_perl, php background).
>
> I can give some more information to hopefully help me grasp this just
> that bit more.
>
> Basically I am creating my own custom blog site for me and a few of my
> friends.  We have wanted our own for a while, but I also have been
> wanting a project to work on so I don't want to use an already created
> one (I have a few ideas of my own that I haven't seen in others that I
> want to attempt).  I started it in PHP, but then noticed django and
> decided to try a new approach to the whole thing.
>
> So basically when I roll it out, the website would have no blogs on
> it, just a front page welcoming me and possibly displaying some
> statistics or news on it and allowing register/login.  So if I were
> the first to create an account, I would gain access to
> www.mysite.com/bbeaudreault
> or whatever and the corresponding apps therein.  If my friend
> registered they would get the same, www.mysite.com/friend1
>
> The kicker is I want them to be able to completely customize the look
> of their blog.  From positioning of the different modules (like recent
> posts, calendar, etc being moved from left to right to top) to color
> scheme, to images on it, and of course disabling certain modules (if
> they don't want a calendar).  Sure this may be more complicated than a
> blog has to be, but these will be added over time and will present a
> nice little project for myself in adding them as I go.
>
> I guess now that I think of it more (if I am hopefully gaining a
> better grasp), when a new user is created I would have to automate an
> adding of a new url to the urls.py file.  And I could probably store
> the resulting CSS from moving modules around, as well as flags for
> enabled/disabled modules in the DB for each user as well.
>
> Does this sound more in line with django's design philosophy?
>
> Oh, and yea I went through the tutorial, and it is great for the
> simple website kinda thing.  I am just having a hard time
> extrapolating that to what I have in mind for this site (explained
> above)
>
> Thanks again,
> Bryan
>
> On Jul 3, 3:33 am, Daniel Hepper <[EMAIL PROTECTED]> wrote:
> > Hi Bryan,
> >
> > maybe I don't quite get what you are trying to do.
> >
> > URLs 
> > likewww.mysite.com/Foo/don'trelate 
> > to filesystem paths
> > (like /home/django/Foo). They are mapped to python functions. This might
> > confuse you if you come from a PHP background. Usually you don't clone
> > project, apps or any kind of code for each user. You have one project
> > which consists of several apps, the information for each user is taken
> > from the database.
> >
> > Have you gone through the tutorial?
> http://www.djangoproject.com/documentation/tutorial01/
> >
> > Maybe you can explain what kind of site you have in mind if you really
> > think you have to clone apps or projects.
> >
> > Regards,
> > Daniel
> >
> > Am Mittwoch, den 02.07.2008, 21:42 -0700 schrieb bbeaudreault:
> >
> > > Hello all,
> >
> > > I just recently started playing around with django, and I am
> > > interested in using it to create a site I have in mind.  I would
> > > appreciate any help in understanding if I have wrapped my head around
> > > the idea of projects and apps properly.
> >
> > > Basically, the site would have a main page that displays generic info
> > > from the DB and allows uers to login/register.
> >
> > > When a new user registers, it would create a new subfolder of the
> > > domain, which would be a clone of some django app/project (the part I
> >

Re: Accessing URL Parameters in Django Templates

2008-07-02 Thread Scott Moonen
Sameer, if you are using the RequestContext object to produce the template
context, then you should be able to access the URL parameters in your
template as request.GET.*parametername*.  In this case, request.GET is a
QueryDict object (see
http://www.djangoproject.com/documentation/request_response/#querydict-objects
).

  -- Scott


On Wed, Jul 2, 2008 at 1:52 PM, Sameer Maggon <[EMAIL PROTECTED]> wrote:

>
> Hi All,
>
> Is there a standard way to access the URL parameters in the Django
> templates? I can write a template tag to do that, but I was hoping I
> could avoid it.
>
> Thanks,
> Sameer.
> --
> http://www.maggon.com
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Greater than Less than

2008-07-02 Thread Scott Moonen
Aah, ok.  I think this might work:

exclude(number_iregex = r'^(1?(281|832|713|800).*|.{,6})$')

That excludes anything that matches your existing pattern or which is
exactly six characters or less.  Please be sure to test it though as this is
off the cuff. :)

  -- Scott

On Wed, Jul 2, 2008 at 12:16 PM, mike171562 <[EMAIL PROTECTED]>
wrote:

>
> Scott,
>
> Thanks, I'm already using long_distance =
> call.exclude(number__iregex=r'^1?(281|832|713|800)')
> to filter long distance numbers so, the new regex would be
>
> something like iregex=r'^1?(281|832|713|800)^.{7,}')
>
> does that look right?
>
>
> On Jul 2, 11:04 am, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > Mike, you might try this:
> >
> > call.filter(number__regex = r'^.{7,}')
> >
> > That uses a regular expression that matches strings of length 7
> characters
> > or more.
> >
> >   -- Scott
> >
> > On Wed, Jul 2, 2008 at 11:59 AM, mike171562 <[EMAIL PROTECTED]>
> > wrote:
> >
> >
> >
> > > hello,
> > >I am working on a web app that pulls call logs from a database
> > > and displays them.  I am working with the greater than and less than
> > > functions to filter out phone numbers less than 7 digits long i.e.
> > > internal extensions. When I use something like
> > > call.filter(number__gte=7) however, it filters  me the value and not
> > > the length. Does anyone know of a way to query for length of a number
> > > and not the actual value?  thx in advance.
> >
> > --http://scott.andstuff.org/|http://truthadorned.org/<http://scott.andstuff.org/%7Chttp://truthadorned.org/>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Greater than Less than

2008-07-02 Thread Scott Moonen
Mike, you might try this:

call.filter(number__regex = r'^.{7,}')

That uses a regular expression that matches strings of length 7 characters
or more.

  -- Scott

On Wed, Jul 2, 2008 at 11:59 AM, mike171562 <[EMAIL PROTECTED]>
wrote:

>
> hello,
>I am working on a web app that pulls call logs from a database
> and displays them.  I am working with the greater than and less than
> functions to filter out phone numbers less than 7 digits long i.e.
> internal extensions. When I use something like
> call.filter(number__gte=7) however, it filters  me the value and not
> the length. Does anyone know of a way to query for length of a number
> and not the actual value?  thx in advance.
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: initializing a model with a dicitonary

2008-07-01 Thread Scott Moonen
Hi, try doing this:

c = Customer(**customerdict).save()


  -- Scott

On Tue, Jul 1, 2008 at 12:56 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:

>
> I have an object called customer that I trying to initialize from a
> large XML parse.  I parse the XML into a dictionary into something
> like
>
> customerdict = {'first_name' : 'mike', 'last_name' : 'c', 'etc' :
> 'etc' } and so forth
>
> then I try to do c = Customer(customerdict).save()
>
> I get a "Can't Adapt" error.
>
> However, if I manually pass in each variable like so:
>
> c = Customer(first_name = customerdict['first_name'], last_name =
> customerdict['last_name']).save()
>
> it works fine.
>
> Passing in each variable would be a huge PITA plus any changes to the
> model would require changes in multiple places while parsing and
> passing the dictionary wouldn't require any changes.  What am I doing
> wrong?
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: dreaded FieldError (used to be KeyError) can only replicate on production, ugh!

2008-07-01 Thread Scott Moonen
Milan, I took another look at the error and your template.  Judging from the
error (it seems to be complaining about some access to the member object,
rather than the project list), I think the reference to line 9 is a red
herring.  In other words, the outermost tag that Django is rendering at the
time is your outer for loop, but the real problem is occurring in the
rendering of an inner loop.

So I'd ignore the reference to line 9 and look further at the inner contents
of that for loop.  I don't think the entire for loop is included in the
dpaste traceback snippet, as I don't see its endfor.

  -- Scott

On Mon, Jun 30, 2008 at 9:18 PM, Malcolm Tredinnick <
[EMAIL PROTECTED]> wrote:

>
>
> On Mon, 2008-06-30 at 16:53 -0700, Milan Andric wrote:
> >
> >
> > On Jun 30, 3:32 pm, Milan Andric <[EMAIL PROTECTED]> wrote:
> > > On Jun 30, 3:08 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > >
> > > > Hi Milan, would you mind posting the source for the object_list
> function as
> > > > well?
> > >
> > > I just imported object_list from django.views.generic.list_detail.
> > >
> >
> > One oddity I think I picked out of the html traceback was in
> > /foobar/django/db/models/query.py in filter
> > return self._filter_or_exclude(False, *args, **kwargs)
> >
> > self is a list of ALL the User objects.  Not sure what is causing all
> > that stuff to be pulled through a seemingly simple view.
>
> I haven't looked at this in detail yet, but I thought I'd head of any
> mid-diagnosis here. It looks more like "self" is a queryset. The debug
> view shows the repr() of each object and the repr() of a queryset if the
> list containing each object. So I'd guess "self" is something like
> User.objects.filter(...).
>
> Regards,
> Malcolm
>
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Programming error 1064 - possibly bad string length?

2008-06-30 Thread Scott Moonen
Actually, I might be misreading the error string.  It looks like the address
field has extra quotes around it too.  Maybe that's just how strings get
formatted in this case and is not the problem...

  -- Scott

On Mon, Jun 30, 2008 at 4:02 PM, Scott Moonen <[EMAIL PROTECTED]> wrote:

> Simon, my guess is that the error doesn't have to do with the truncation
> you see, but that something that is passing the error along is trying to be
> helpful by truncating the string -- one hopes in such a way that the error
> is still evident. :)
>
> Looking at the snippet you've posted, I wonder how the 'gender' field is
> defined.  You are storing the three-character string 'Y' into it (including
> single quotes).  Do you expect to be able to store three characters into it,
> or only one character?
>
>   -- Scott
>
>
> On Mon, Jun 30, 2008 at 3:47 PM, Simon Tite <[EMAIL PROTECTED]> wrote:
>
>>
>> I get the following error when trying to save a model -
>> "userprofile.save()" -
>>
>> (1064, 'You have an error in your SQL syntax; check the manual that
>> corresponds to your MySQL server version for the right syntax to use
>> near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
>> ("\'97 Rochdale Rdrn\' at line 1')
>>
>> The data comes from a form, one of the fields being "address". It
>> would appear that the final part < `address` = ("\'97 Rochdale Rdr\
>> \\\n\'  > does not have a closing parenthesis.
>>
>> If I put more data into the textbox for the address field, this is the
>> result:
>>
>> ProgrammingError at /form/profile/
>> (1064, 'You have an error in your SQL syntax; check the manual that
>> corresponds to your MySQL server version for the right syntax to use
>> near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
>> ("\'97 Rochdale Manor Ho\' at line 1')
>>
>> This seems like there is a larger SQL command, which has been
>> truncated at exactly the same character position. This theory is borne
>> out by other experiments: if the address field is left blank, the next
>> field "telephone" is truncated at the same position...
>>
>> This is the version of mySql:-
>>
>> $ mysql -V
>> mysql  Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using
>> readline 5.2
>> $
>>
>> I'm using Django trunk 7788, from +/- 0100 GMT today 30/6/2008.
>>
>> So, I wonder how I can look at the full text of the string which is
>> being passed to mySql, and whether anyone knows of any string size
>> limitation in Django SQL statements (this seems unlikely, as I would
>> probably have found it in the forum somewhere: there are lots of posts
>> about error 1064, but none AFAIK seem to reflect my problem), or maybe
>> there is a mySql setting which allows/disallows incomplete lines?
>> Maybe Django was going to follow with the rest of the statement, but
>> mySql threw an error?
>>
>> Hmmm. Think I'll re-read the mySql manual... but in the meantime, does
>> anyone have any ideas?
>> >>
>>
>
>
> --
> http://scott.andstuff.org/ | http://truthadorned.org/




-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: dreaded FieldError (used to be KeyError) can only replicate on production, ugh!

2008-06-30 Thread Scott Moonen
Hi Milan, would you mind posting the source for the object_list function as
well?

  -- Scott

On Mon, Jun 30, 2008 at 4:01 PM, Milan Andric <[EMAIL PROTECTED]> wrote:

>
> I've been wresting with this one for a couple hours now trying to
> track it down, but no luck.  I'm recently updated to django trunk and
> getting very odd reponses.  I could take the same page and refresh it
> several times in succession and eventually get the page, but usually
> get 500 errors.  What would cause that?
>
> http://multimedia.journalism.berkeley.edu/training/projects/
>
> I also restarted/stop/started and removed all .pyc files from my
> project, installed apps and django just for good measure.
>
>  I managed to get the traceback while in debug mode that raises a
> FieldError:
> http://dpaste.com/5/
>
> Here's the wrapped generic view that is being called:
> http://dpaste.com/60002/
>
> Here's the model:
> http://dpaste.com/60005/
>
> I also have copied the production database into a dev environment
> using the built-in webserver and verified  code versions are the same
> (django and my project). I cannot replicate the problem in dev
> environment so it's kind of a pain to debug.  Not sure what other
> software components to look at that would squelch or avoid the error
> in my dev environment.  The only main difference is I'm using the
> built-in webserver and MySQL5 instead of MySQL4.
>
> Any help is greatly appreciated,
>
> --
> Milan
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Programming error 1064 - possibly bad string length?

2008-06-30 Thread Scott Moonen
Simon, my guess is that the error doesn't have to do with the truncation you
see, but that something that is passing the error along is trying to be
helpful by truncating the string -- one hopes in such a way that the error
is still evident. :)

Looking at the snippet you've posted, I wonder how the 'gender' field is
defined.  You are storing the three-character string 'Y' into it (including
single quotes).  Do you expect to be able to store three characters into it,
or only one character?

  -- Scott

On Mon, Jun 30, 2008 at 3:47 PM, Simon Tite <[EMAIL PROTECTED]> wrote:

>
> I get the following error when trying to save a model -
> "userprofile.save()" -
>
> (1064, 'You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
> ("\'97 Rochdale Rdrn\' at line 1')
>
> The data comes from a form, one of the fields being "address". It
> would appear that the final part < `address` = ("\'97 Rochdale Rdr\
> \\\n\'  > does not have a closing parenthesis.
>
> If I put more data into the textbox for the address field, this is the
> result:
>
> ProgrammingError at /form/profile/
> (1064, 'You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
> ("\'97 Rochdale Manor Ho\' at line 1')
>
> This seems like there is a larger SQL command, which has been
> truncated at exactly the same character position. This theory is borne
> out by other experiments: if the address field is left blank, the next
> field "telephone" is truncated at the same position...
>
> This is the version of mySql:-
>
> $ mysql -V
> mysql  Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using
> readline 5.2
> $
>
> I'm using Django trunk 7788, from +/- 0100 GMT today 30/6/2008.
>
> So, I wonder how I can look at the full text of the string which is
> being passed to mySql, and whether anyone knows of any string size
> limitation in Django SQL statements (this seems unlikely, as I would
> probably have found it in the forum somewhere: there are lots of posts
> about error 1064, but none AFAIK seem to reflect my problem), or maybe
> there is a mySql setting which allows/disallows incomplete lines?
> Maybe Django was going to follow with the rest of the statement, but
> mySql threw an error?
>
> Hmmm. Think I'll re-read the mySql manual... but in the meantime, does
> anyone have any ideas?
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Group by week

2008-06-26 Thread Scott Moonen
Chris, I have a utility function that does this for me.  You can call it
from your view, or if you set things up right from your template:

from datetime import date
def most_recent_Sunday(dt = None) :
  if dt is None : dt = date.today()
  return date.fromordinal(date.toordinal(dt) - (dt.weekday() + 1) %7)

  -- Scott

On Thu, Jun 26, 2008 at 11:36 AM, Chris H. <[EMAIL PROTECTED]>
wrote:

>
> I have a view which returns a group of upcoming events.  I would like
> to display the events grouped by week:
>
> Week of June 22
> * Event 1
> * Event 2
> * Event 3
>
> Week of June 29
> * Event 4
> * Event 5
> * Event 6
>
> I've seen examples for doing this using the ifchanged tag, and I've
> got that working.  But I can't seem to figure out how to display the
> beginning of the week as the heading since the first event isn't
> always a Sunday.  Any thoughts or pointers?
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: views.py: Always a simple return?

2008-06-26 Thread Scott Moonen
Ross, I had one more thought.

Are most browsers capable of using persistent HTTP for XMLHttpRequests?  If
so, and *assuming your main motivation is simply to be more efficient by
using a single HTTP connection* for your traffic, then I think you might be
able to implicitly exploit persistent HTTP to get what you want.  If you use
a pull model rather than a push model, and have the client make its requests
frequently enough that most browsers' timeouts don't tear down the
persistent HTTP connection, and if you ensure that your responses are
suitable for use with persistent HTTP (i.e., they contain a valid
Content-Length header), then I think you may satisfy your goal.

  -- Scott

On Thu, Jun 26, 2008 at 10:33 AM, Scott Moonen <[EMAIL PROTECTED]> wrote:

> Ross, it seems to me that there are a number of potential hurdles to
> holding a connection open for a long period:
>
>1. Some server configurations may require that requests be satisfied
>within a certain time period or else the connection will be reset.  Of
>course, since the server is under your control, you can probably ensure 
> this
>is not an issue.
>2. It seems possible to me that some browsers may have problems with
>this approach.  Specifically, they might not be willing to hold connections
>open for longer than a certain period, or they may not have a reliable 
> means
>for Javascript to access the partial data, or they may not have a means for
>Javascript to discard the already-read data (resulting in memory creep).
>I'm not sure any of these are the case, lacking personal experience in this
>area, but they are things you'd need to research and satisfy yourself of
>across multiple browsers and platforms.  Certainly there are Flash 
> streaming
>applications out there, so if you can elect to use Flash (or some other
>plugin) on the client-side then some of these client-side questions may go
>away.
>3. Many firewalls, intrusion detection systems, proxies, and NATs will
>likely have issues with long-running HTTP connections.  It is possible that
>a firewall or IDS will reset such connections; it is possible that a NAT
>mapping expiration will sever the connection (especially if the data is
>intermittent rather than continuous); and it is possible that a proxy
>reassignment (think AOL) or other configured proxy restrictions (e.g.,
>connection lifetime limits) will disrupt the connection as well.  Again,
>there are a large number of environments here you need to consider.  Some 
> of
>these issues may go away if you use a port other than 80, but many
>intermediate hosts are still smart enough to discover that you are using
>HTTP regardless of the port value.
>4. In cases where the data to be pushed is intermittent you may also
>need to enable and configure TCP keepalives to ensure that your connections
>and server threads don't linger any longer than necessary.
>5. How many clients do you expect to have?  If it's a large number,
>then you should weigh the potential cost of having many server-side request
>processing threads open simultaneously.  You may also find that you hit
>configuration limits on Apache threads (and Django threads if you are
>running using WSGI) that need to be raised.
>6. Performance is also a consideration here; what sort of model will
>these threads use to suspend or throttle themselves?  Will they select on
>some event that wakes them up to trigger a new notification?  Will they
>sleep for a specified amount of time and execute a query to determine if 
> new
>data is to be sent?  How will you ensure they aren't doing busy waits?  (By
>comparison, performance is of course still an issue for polling requests
>initiated by the client, there are just a different set of questions to be
>answered in that case.)
>7. If #5/#6 brought up a number of limitations, you might need to
>consider a server model that didn't couple threads to requests, but instead
>to some smaller transactional unit of work.  A thread could complete a
>transaction without the overall HTTP request being considered complete or
>the connection being closed.  Here you're ranging far out of normal HTTP
>territory and I'm not sure that most HTTP servers will suit your needs.  
> The
>good news is that you could still use Django's ORM for your database needs,
>but you'd probably not be able to use its url/view/template architecture. 
> :)
>
> It's certainly a very interesting set of problems to solve!  And this is
> not at all a bad model in general for some client-server applications.  But
> there are enoug

Re: views.py: Always a simple return?

2008-06-26 Thread Scott Moonen
Ross, it seems to me that there are a number of potential hurdles to holding
a connection open for a long period:

   1. Some server configurations may require that requests be satisfied
   within a certain time period or else the connection will be reset.  Of
   course, since the server is under your control, you can probably ensure this
   is not an issue.
   2. It seems possible to me that some browsers may have problems with this
   approach.  Specifically, they might not be willing to hold connections open
   for longer than a certain period, or they may not have a reliable means for
   Javascript to access the partial data, or they may not have a means for
   Javascript to discard the already-read data (resulting in memory creep).
   I'm not sure any of these are the case, lacking personal experience in this
   area, but they are things you'd need to research and satisfy yourself of
   across multiple browsers and platforms.  Certainly there are Flash streaming
   applications out there, so if you can elect to use Flash (or some other
   plugin) on the client-side then some of these client-side questions may go
   away.
   3. Many firewalls, intrusion detection systems, proxies, and NATs will
   likely have issues with long-running HTTP connections.  It is possible that
   a firewall or IDS will reset such connections; it is possible that a NAT
   mapping expiration will sever the connection (especially if the data is
   intermittent rather than continuous); and it is possible that a proxy
   reassignment (think AOL) or other configured proxy restrictions (e.g.,
   connection lifetime limits) will disrupt the connection as well.  Again,
   there are a large number of environments here you need to consider.  Some of
   these issues may go away if you use a port other than 80, but many
   intermediate hosts are still smart enough to discover that you are using
   HTTP regardless of the port value.
   4. In cases where the data to be pushed is intermittent you may also need
   to enable and configure TCP keepalives to ensure that your connections and
   server threads don't linger any longer than necessary.
   5. How many clients do you expect to have?  If it's a large number, then
   you should weigh the potential cost of having many server-side request
   processing threads open simultaneously.  You may also find that you hit
   configuration limits on Apache threads (and Django threads if you are
   running using WSGI) that need to be raised.
   6. Performance is also a consideration here; what sort of model will
   these threads use to suspend or throttle themselves?  Will they select on
   some event that wakes them up to trigger a new notification?  Will they
   sleep for a specified amount of time and execute a query to determine if new
   data is to be sent?  How will you ensure they aren't doing busy waits?  (By
   comparison, performance is of course still an issue for polling requests
   initiated by the client, there are just a different set of questions to be
   answered in that case.)
   7. If #5/#6 brought up a number of limitations, you might need to
   consider a server model that didn't couple threads to requests, but instead
   to some smaller transactional unit of work.  A thread could complete a
   transaction without the overall HTTP request being considered complete or
   the connection being closed.  Here you're ranging far out of normal HTTP
   territory and I'm not sure that most HTTP servers will suit your needs.  The
   good news is that you could still use Django's ORM for your database needs,
   but you'd probably not be able to use its url/view/template architecture. :)

It's certainly a very interesting set of problems to solve!  And this is not
at all a bad model in general for some client-server applications.  But
there are enough issues unique to using HTTP as a transport that would make
solving these problems for all possible environments, and with good
performance characteristics, fairly costly.

  -- Scott

On Thu, Jun 26, 2008 at 9:40 AM, RossGK <[EMAIL PROTECTED]> wrote:

>
>
>
> On Jun 25, 4:56 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> > Generally with HTTP, you would configure your server to continue to
> respond
> > to requests;)  Which is exactly what django does anyway.
>
> That's my question - rather than one response to a request I'd like to
> have several responses.  For example a user requests continuous
> traffic information and the server replies with continuous replies of
> the number of cars per second. So one reply with multiple answers,
> with the TCP connection left open until the data flow reaches a
> condition (e.g. fewer than  5 cars per second).
>
> > HTTP is a connection based (TCP) protocol, but the connection is closed
> once
> > the return has been sent.  Hence the need to store a 'session' variable
> in
> > the server and use a cookie on the browser with a corresponding session
> id.
> > Data does not live beyond the request.  You ca

Re: very heavy problem with edit_inline

2008-06-21 Thread Scott Moonen
Yes, I think it is incorrect.  It should be set on some field that the user
can type in and which must not be blank.  Then, when that field is left
blank, the admin will actually delete the address.  I recommend setting
core=True on the indirizzo field.

  -- Scott

On Sat, Jun 21, 2008 at 2:39 PM, Alessandro Ronchi <
[EMAIL PROTECTED]> wrote:

> 2008/6/21, Scott Moonen <[EMAIL PROTECTED]>:
> > Alessandro, see the documentation for the "core" model field option:
> > http://www.djangoproject.com/documentation/model-api/#core
> >
> > You should set core=True on some field that must otherwise be present in
> an
> > address.  Looks like "indirizzo" is such a field.
>
> I've set core=True on my impresa field (the one with edit_inline=
> True). Is it wrong?
>
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: very heavy problem with edit_inline

2008-06-21 Thread Scott Moonen
Alessandro, see the documentation for the "core" model field option:
http://www.djangoproject.com/documentation/model-api/#core

You should set core=True on some field that must otherwise be present in an
address.  Looks like "indirizzo" is such a field.

  -- Scott

On Sat, Jun 21, 2008 at 7:37 AM, Alessandro Ronchi <
[EMAIL PROTECTED]> wrote:

> I am trying to let admin users edit related field in one single page.
>
> I have a company model that has many addresses, so I've decided to use
> a Company model and an Address model with foreignkey(Company,
> edit_inline=models.STACKED)
> It works correcly until I've edit the company: IT DELETES ALL MY
> ASSOCIATED ADDRESSES if I click on Save() of my company.
>
> How can I avoid this?
> Is there a solution?
>
> Anyone uses edit_inline without problems?
>
> class Impresa(models.Model):
>codice = models.CharField(max_length=10,blank=False,  primary_key=True)
>utente = models.ForeignKey(User, blank=True, null=True, unique=True)
>ragione_sociale = models.CharField(max_length=100)
>
> class Indirizzo(models.Model):
>impresa = models.ForeignKey(Impresa)#, edit_inline=models.STACKED,
> core=True, related_name="indirizzi")
>tipologia= models.CharField(max_length=2, blank=True, null=True,
> choices=TIPO_INDIRIZZO)
>indirizzo = models.CharField(max_length=100)
>cap = models.CharField(max_length=10, blank=True, null=True)
>citta = models.CharField(max_length=100, blank=True, null=True)
>provincia = models.CharField(max_length=2, blank=True, null=True,
> choices=PROVINCE, default='FC')
>
>
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Many To Many view in admin

2008-06-20 Thread Scott Moonen
Alessandro,

It shows all the addresses inline of only the first?
>

It will show all of them inline.  See
http://www.djangoproject.com/documentation/model-api/#many-to-one-relationshipsand
scroll down to the description of "edit_inline".

  -- Scott Moonen

On Fri, Jun 20, 2008 at 8:48 AM, Alessandro Ronchi <
[EMAIL PROTECTED]> wrote:

> 2008/6/20 Scott Moonen <[EMAIL PROTECTED]>:
> > Alessandro, if an address is for only one company, then I suggest that
> you
> > remove the ManyToManyField, and instead put a ForeignKey within the
> Address
> > model that references Company.  If you set the edit_inline parameter on
> this
> > ForeignKey you should be able to edit the address right on the company
> page
> > in the admin app.
>
> It shows all the addresses inline of only the first?
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Many To Many view in admin

2008-06-20 Thread Scott Moonen
Alessandro, if an address is for only one company, then I suggest that you
remove the ManyToManyField, and instead put a ForeignKey within the Address
model that references Company.  If you set the edit_inline parameter on this
ForeignKey you should be able to edit the address right on the company page
in the admin app.

  -- Scott

On Fri, Jun 20, 2008 at 8:21 AM, Alessandro <[EMAIL PROTECTED]>
wrote:

> I have a model company with a ManyToManyField(Address)
> An Address is for only one company, but a company has more than one
> Address.
>
> I need to be able to view in my admin page only the addresses of my
> company, not the list of all addresses, and maybe edit the address
> details (or open it in a new window, like one does when he add a new
> address).
>
> Is it possible?
>
> How?
>
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Template engine

2008-06-13 Thread Scott Moonen
Would it be possible to borrow from the embedded ruby syntax and define
something like this:

{{ variable.name -}}
{% tag param1,param2 -%}

If the '-' was present as part of the tag closure token, the template
processor would eat the next 1-2 characters only if they were a CR or CR/LF.

Although I suppose this might cause problems for some tags that had
begin/end pairs,

  -- Scott

On Fri, Jun 13, 2008 at 1:43 PM, Norman Harman <[EMAIL PROTECTED]>
wrote:

>
> Russell Keith-Magee wrote:
> > If there is a particular whitespace-eating behaviour that you would
> > like, you could always implement it yourself in a template tag. If you
> > think the template tag could be useful for others, you can share it on
> > djangosnippets.org, or open a ticket to have the tag considered for
> > inclusion in Django itself.
> >
> > If what you're proposing can't be done in a template tag, we're always
> > open to suggestions on how to make Django better. Put down your ideas
> > in a ticket, and we'll consider it.
>
> What I'm use to is less of particular tag and more of a change to how
> all tags/templates work.  In short, lines in templates that have only
> tags should be "invisible" i.e. they should not be in the output of that
> template.
>
> If after doing tag processing a line(that had 1+ tags to begin with)
> consists of nothing but whitespace then eliminate that line, including
> it's new line.
>
> line numbers for ref:
> 1: {% if bar %}bar{% endif %}
> 2: {% for i in list %}
> 3:   i
> 4:   {% if False %}{% endif %}
> 5: {% endfor %}
> 6: 
>
> which now creates something like this when bar=False, list=[1,2]
> 1:
> 2:
> 3:  1
> 4:
> 3:  2
> 4:
> 5:
> 6:
>
> instead outputs this
> 1:
> 3:  1
> 3:  2
> 6:
>
>
> But this is a backwards incompatible change, a minor issue, and with
> effort it's possible to work around this issue just not beautifully
> (which contrasts with the rest of Django).
>
> Other stuff is higher priority and the real problem with Django is
> http://superjared.com/entry/real-problem-django/.  I didn't mean to
> sound complainy in previous post, if anyone took it that way.
>
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> ___
> You've got fun!  Check out Austin360.com for all the entertainment
> info you need to live it up in the big city!
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Filtering a query based on potential arguments

2008-06-12 Thread Scott Moonen
You can take advantage of the fact that query sets are not executed until
they are inspected:

cards = Card.objects.all()
if request.POST.get('brand') :
  cards = cards.filter(brand = request.POST.get('brand'))
if request.POST.get('year') :
  cards = cards.filter(year = request.POST.get('year'))
. . .

  -- Scott

On Thu, Jun 12, 2008 at 5:42 AM, caustic <[EMAIL PROTECTED]> wrote:

>
>
>
> On Jun 12, 10:55 am, truebosko <[EMAIL PROTECTED]> wrote:
> > I have a card store and I would like to add 3 options a user can
> > search by. Year, Brand, and Card Title
> >
> > Normally this would be easy but my dilemna here is:
> > - All of these are optional, and if they do not search for a certain
> > one, the query should ignore that filter entirely and display in full
> > (So if none of the filters are active I display ALL cards)
> >
> > So basically what I am thinking of was:
> >
> > if request.POST.get('brand'):
> > Q(brand=request.POST.get('brand')
> >
> > if request.POST.get('year'):
> > Q(year=request.POST.get('year')
> >
> > etc.
> >
> > cards = Card.objects.filter(... Now how do I get those Q objects into
> > here ??).order_by('pk')
>
> Try
> cards = Card.objects.filter(Q1&Q2)
>
> Alternatively you can use a dictionary and ** magic:
> filter = dict(brand=request.POST.get('brand'),
> year=request.POST.get('year'))
> cards = Card.objects.filter(**filter)
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Text Formatting

2008-06-09 Thread Scott Moonen
You'll need to use some sort of rich text editor.  I've used
TinyMCEin the past; there are others as
well.

  -- Scott

On Mon, Jun 9, 2008 at 9:51 AM, yanksluvr7 <[EMAIL PROTECTED]> wrote:

>
> Is there a way to make a django page so you can copy and paste text
> into the page and have it keep its original formatting? Everything I
> have found makes it copy as plain text, so any spacing, bullets, bold,
> italics, or anything else is lost.
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: why my django site doesn't create .pyc file?

2008-06-09 Thread Scott Moonen
>
> I think this way, apache could be a little more faster. Am I right?
>

I don't think it will be faster.  Django normally runs as a long-standing
process (either inside Apache or as a standalone process, depending on the
deployment model you've chosen).  So, unlike ordinary CGI scripts, your
Python bytecode will not need to be generated except for the very first time
that your code is loaded.  Once it's up and running it will already be in
memory so it won't need to be reinterpreted.

I personally don't think the trade-off is worth it here.  You're giving
Apache write access to your source code (which may not be much of a security
risk relative to other things like the fact that Apache has access to your
database, but it is definitely a blurring of privilege boundaries), and
you're not getting any long-running performance benefit from it; only a
slight initial load benefit.


  -- Scott

On Mon, Jun 9, 2008 at 9:40 AM, pength <[EMAIL PROTECTED]> wrote:

>
> Thanks a lot !
>
> I changed the user information in apache2's conf file, and now it's
> OK!
>
> I think this way, apache could be a little more faster. Am I right?
>
> On 6月9日, 下午7时39分, "Valts Mazurs" <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > Check if web server process has enough privileges to write in the
> > directories containing .py files.
> >
> > Regards,
> > Valts.
> >
> > On Mon, Jun 9, 2008 at 1:25 PM, pength <[EMAIL PROTECTED]> wrote:
> >
> > > I have justed built my site on slicehost. Alhough my site is running
> > > properly, I found if I update any  file (.py file, of course), it
> > > never recreate the .pyc file. Actually, if I delete any .pyc file,
> > > then it will never appear.
> >
> > > I think there's something wrong with my site config, can anyone give
> > > me any hint?
> >
> > > I am using nginx as front proxy server and static file server, apache2
> > > and mod_python as backend.
> >
> > > Thanks!
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Missing calender button in Django Administration

2008-05-30 Thread Scott Moonen
>From an earlier email to this list, it sounds like the calendar doesn't work
on 0.96.2 if USE_I18N is set to True in your settings.py file.  This seems
resonable to me; at one point I tried to use the calendar from my own
templates but tripped over needing to define or stub out some gettext
routines in my Javascript.  I ended up using something else in my own
templates. :)

I have found the SVN version to be quite stable, and if you are at the early
enough stage of working through tutorials I would recommend that you move to
the SVN version from here on out.

  -- Scott

On Fri, May 30, 2008 at 9:03 AM, lenz <[EMAIL PROTECTED]> wrote:

>
> Seems that everything is ok if i use the latest svn version of django!
> Maybe the calender is just a new feature? But i am working with
> tutorial for 0.96
> So maybe a failure in the tut! But how can new features get into to
> old tutorials?
>
> Anyway - sorry for bothering!
>
> Lenz
>
> On May 30, 2:41 pm, lenz <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > i am very new to django and following the tutorial from the django
> > docs.
> > At the moment i am here:
> http://www.djangoproject.com/documentation/0.96/tutorial02/#explore-t...
> >
> > My poblem is:
> > when i log in to the Django Administration und try to edit the polls
> > everthing works
> > fine except that the calender button, the today link, the clock button
> > and the now link are missing.
> >
> > I am using django Version 0.96.2 on Mac OS X
> >
> > Thanks in advance!
> >
> > Lenz
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: Session logout behaviour

2008-05-29 Thread Scott Moonen
Louis, there is some value in retaining the session past logout.  The
decision of what session data to keep/destroy is best left to the
application.  For any application that allows both anonymous and
authenticated access, any site settings that you are able to set as an
anonymous user (e.g., font size) should be able to persist across logout.
Or consider the case of an application that is able to remember your login
id in its login form -- that, too, would remain in your session after
logout.

  -- Scott

On Thu, May 29, 2008 at 5:59 AM, Louis Cordier <[EMAIL PROTECTED]> wrote:

>
> From http://www.djangoproject.com/documentation/sessions/ it follows,
>
> Clearing the session table
> =
> ...
> To understand this problem, consider what happens when a user uses a
> session. When a user logs in, Django adds a row to the django_session
> database table. Django updates this row each time the session data
> changes. If the user logs out manually, Django deletes the row. But if
> the user does not log out, the row never gets deleted.
>
> But in actual fact Django never deletes the row on logout.
>
> In trunk/django/contrib/auth/__init__.py
>
> ---8<--
> def logout(request):
>"""
>Remove the authenticated user's ID from the request.
>"""
>try:
>del request.session[SESSION_KEY]
>except KeyError:
>pass
>try:
>del request.session[BACKEND_SESSION_KEY]
>except KeyError:
>pass
>if hasattr(request, 'user'):
>from django.contrib.auth.models import AnonymousUser
>request.user = AnonymousUser()
> ---8<--
>
> It only deletes '_auth_user_id' and '_auth_user_backend' from the
> session, but keep the rest in tact.
> If a new user logs in with this browser (without closing it first and
> thus deleting the session cookie)
> the session middleware takes the session cookie and instantiates a
> SessionStore with it.
>
> request.session = engine.SessionStore(session_key)
>
> This effectivly gives the new user the previous user's (polluted) session.
>
> An easy fix would be to actually delete the row as stated in the
> documentation.
> ---8<--
> from django.conf import settings
>
> def logout(request):
>try:
>
>  request.session.delete(request.COOKIES[settings.SESSION_COOKIE_NAME])
>except KeyError:
>pass
> ...
> ---8<--
>
> My questions are:
>
> * Is there a good reason why the sessions are not cleared at manual logout
> ?
> * Is there an alternative method of dealing with this situation,
> polluted sessions ?
> * Is this a bug, should I file a ticket ?
>
> Regards Louis.
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: How to change admin interface text boxes to text areas?

2008-05-28 Thread Scott Moonen
Emily, I suspect you have defined these particular fields as a CharField.
Have you tried defining them as a TextField instead?

  -- Scott Moonen

On Wed, May 28, 2008 at 7:59 AM, emy_66 <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I'm new at Django and is wondering if anyone knows how to change the
> text boxes that appear in the edit section of the admin pages to text
> areas? A couple of my attributes are very long strings with '\n' in
> them and when they appear in the text boxes only the first line
> appear. It would be great to be able to have text areas with scroll
> bars for those attributes.
>
> Thanks in advance,
>
> Emily
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: IntegerField with choices raising an TypeError

2008-05-22 Thread Scott Moonen
I suspect your problem may be due to the fact that your display value for 3
is a number rather than a string.  Try changing:

   CHOICES = [(1, '1'), (2, '2'), (3, 3), (4, '4'), (5, '5')]

to

   CHOICES = [(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')]


  -- Scott

On Wed, May 21, 2008 at 7:33 PM, Jashugan <[EMAIL PROTECTED]> wrote:

>
> Hello I have the following code in my model:
>
> class SomeMode(models.Model):
>
>CHOICES = [(1, '1'), (2, '2'), (3, 3), (4, '4'), (5, '5')]
>
>score = models.IntegerField(choices=CHOICES)
>
>
> When I change the score in the admin interface it throws this error:
>
> an integer is required
>
> I think this is a bug, but I have only been working with Django for
> the last few days, so wasn't sure. I quickly searched the Trac ticket,
> but didn't find any open tickets related to this. Is this expected
> behavior?
>
> Another thing is that Django actually saves the record to the
> database, even though it gives me the error message.
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: postgresql 8.3 and ILIKE

2008-05-20 Thread Scott Moonen
Gacha, see my bug report and a possible fix (it is currently working for me)
at:

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

  -- Scott

On Tue, May 20, 2008 at 4:14 AM, Gacha <[EMAIL PROTECTED]> wrote:

>
> I upgraded Postgresql to 8.3 version and got an error in admin:
>
>ProgrammingError: operator does not exist: smallint ~~* unknown
>LINE 1: ...js_id" = '6538'  AND "assort_apstlaiks"."a_diena" ILIKE
> '2'
> ^
>HINT:  No operator matches the given name and argument type(s).
> You might need to add explicit type casts.
>
> The field "a_diena" is an integer and from 8.3 version as changelog
> says "Non-character data types are no longer automatically cast to
> TEXT", so this sounds like bug.
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Error in new project creation

2008-05-19 Thread Scott Moonen
Swapna, did you install Django from SVN?  If you extract Django from SVN, it
creates the following directory tree:

django-trunk/ (it looks like you may have renamed this to django/)
django/
docs/
examples/
. . .

Notice that there's a "django" *sub*-directory there.  I'm not sure if
you're using PYTHONPATH to point to Django, or if you're creating a symbolic
link in your site-packages directory.  But either way, you should point at
the "django" sub-directory and not the top-level directory.

  -- Scott

On Mon, May 19, 2008 at 6:44 AM, swapna <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> i am new to Django.After installing Django, i tried to create a new
> project called 'startproject' by giving the command-
> 'django-admin.py startproject mysite'
>
> the above command gave this error
>
> Traceback (most recent call last):
>  File "C:\Django-0.96.2.tar\Django-0.96.2\Django-0.96.2\django\bin
> \django-admin.py", line 2, in 
>from django.core import management
> ImportError: No module named core
>
>
> 1) I  updated the environmental variable.
> 2)i reinstalled both python and Django
>
> but i am encountering the same error.
>
> please let me know how can i solve this...
>
> Thanks in Advance
>
> Swapna
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Dynamic lookup

2008-05-17 Thread Scott Moonen
Toni, you can do this, for example:

fieldname1 = "field"
fieldname2 = "field2__ge"
model.objects.filter(**{ fieldname : variable, fieldname2 : variable2})

  -- Scott

On Sat, May 17, 2008 at 7:11 AM, mwebs <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I am using something like this:
>
> model.objects.filter(field = variable)
>
> Is it possible to pass the field that is used for the lookup
> dynamically, so that field is also a variable ?
>
> Thanks, Toni
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: Reference to the url of the current page in a template

2008-05-16 Thread Scott Moonen
Ganesh,

First ensure that your TEMPLATE_CONTEXT_PROCESSORS contains:

TEMPLATE_CONTEXT_PROCESSORS = (
  . . .
'django.core.context_processors.request',
  . . .
)

Then you can use the variable {{ request.path }} in your templates, assuming
that the URLs are all on the same host.  If not, you'll need to use
something like {{ request.META.HTTP_HOST }}://{{ request.path }}.

  -- Scott


On Fri, May 16, 2008 at 12:58 PM, M.Ganesh <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I don't know how to clearly explain what I want to know. Let me try once
> again...
>
> I have a small controlpanel page which I include in all my other pages.
> This control panel page has got a link to 'login' page. Users are
> allowed to view the pages without login, but they have to login if they
> want to make any changes to the data. So if somebody realises he wants
> to change the data he is currently viewing, he will click the login
> link. Now I want him to be brought back to the page he was viewing
> before logging in. The trouble is because the 'login' link is in a
> template which will get included to a arbitrary page. In other words :
>
> #my controlpane.html
>
> {% if user.is_anonymous %}
>Welcome 
>   Please login
>login
> {% else %}
>blah blah
> {% endif %}
>
>
> Regards Ganesh
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: This field is required. NO!

2008-05-16 Thread Scott Moonen
Andre, in addition to saying null=True, try adding blank=True.

  -- Scott

On Fri, May 16, 2008 at 8:06 AM, Andre Meyer <[EMAIL PROTECTED]>
wrote:

> hi all
>
> now, this is driving me crazy. this problem persists even after switching
> from 0.96.1 to the newforms-admin branch.
>
> after declaring a model class with an attribute that may be null (pn) the
> admin site still tells me to fill in that field, because "This field is
> required.", but it isn't.
>
> i have registered the model class to the admin site without any custom
> options.
>
> recreated the database file (sqlite) after switching to the na branch.
>
> checked in SQLite Manager that the pn field may indeed be null.
>
> new Dossier instances can be created and saved in the shell without the pn
> attribute, but when viewing the instance on the admin page and pressing
> Save, the error appears.
>
> what is the matter?
>
> thanks for your suggestions
> cheers
> André
>
>
> code:
>
> *model.py
> *
> class Dossier(models.Model):
> an = models.CharField('Dossier number', max_length=10,
> primary_key=True)
> pn = models.CharField('Publication number', max_length=20, null=True)
>
> def __unicode__(self):
> return self.an
>
> admin.site.register(Dossier)
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: MySQL Boolean vs. PostgresQL Boolean

2008-05-15 Thread Scott Moonen
You should find that Django's BooleanField understands the difference
between the databases and does the right thing.

  -- Scott

On Thu, May 15, 2008 at 1:57 PM, Szaijan <[EMAIL PROTECTED]> wrote:

>
> Hi, I developed my first Django app on my mapbook using PostgreSQL and
> have recently moved it to a production site which uses MySQL.
> PostgreSQL stores boolean values and True and False, just like Python
> and JS, while MySQL uses 1 and 0.
>
> Is there some automated way to get the models to understand this and
> present/save boolean values to and from views, or do I need to
> override the save and get methods so that they translate 0 to False, 1
> to True, and vice versa?  This seems to be a barrier to portability if
> I have to hard code DB awareness into my models.
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: capturing keyword and non-keyword arguments from urls

2008-05-14 Thread Scott Moonen
Berco, named and unnamed arguments shouldn't be mixed.  See:

http://www.djangoproject.com/documentation/url_dispatch/#the-matching-grouping-algorithm

What the second paragraph means is that the URL handler is trying to call
new(request, name = 'default') and (understandably) it is not working.  You
should change the id into a named argument.

  -- Scott

On Wed, May 14, 2008 at 11:32 AM, Berco Beute <[EMAIL PROTECTED]> wrote:

>
> I want to capture an 'id' and a 'name' from a url (slug) and pass them
> to a method with signature new(request, id, name='default'). For
> example I want to capture '8' and 'newname' from:
> /new/8/newname
>
> Somehow the following url dispatchers work and don't work. The error
> says there is a non-keyword argument missing. What am I doing wrong?
>
> urls.py
> ==
> FAILS: (r'^new/(\d+)/(?P\w+)/$', 'app.views.new'),
> FAILS: (r'^new/(\d+)/(?P[a-z]+)/$', 'app.views.new'),
> WORKS: (r'^new/(\d+)/(\w+)/$', 'app.views.new'),
>
> views.py
> ==
> def new(request, id, name='default'):
>...
>
> Error
> ==
> new() takes at least 2 non-keyword arguments (1 given)
>
>
> Passed variables:
> ==
> callback_args   ()
> callback_kwargs {'name': u'newname'}
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: symmetrical associations

2008-05-14 Thread Scott Moonen
James, one thing you might consider is creating an M2M relation between
edges and nodes.  That won't allow you to enforce at a database level the
rule that edges relate to exactly one or two nodes, but it will work pretty
naturally at the model level -- each node has a set of related edges, and
each edge has a set of related nodes.

  -- Scott

On Wed, May 14, 2008 at 3:43 AM, James Tauber <[EMAIL PROTECTED]> wrote:

>
> On a couple of occasions, I've had need for a model that links two
> instances of another model and I'm wondering about the best practices
> for doing this.
>
> Abstractly, there's an undirected graph where both nodes and arcs are
> objects.
>
> Concretely, two examples are:
>
> 1) roads in django-mmo existing between two hubs but the roads aren't
> directed: A to B means the same as B to A
>
> 2) friendship in django-friends existing between two users where
> friendship is necessarily mutual:  a Friends b => b Friends a
>
> Obviously this can be done with Road or Friendship having two foreign
> keys but (a) this leads to a superfluous related_name; (b) how do you
> best query a node for its arcs?
>
> If the arc were just a M2M field on the node, one could use
> symmetrical=True but it isn't clear to me the best way to do this
> where the arc/association is its own model.
>
> James
> --
> James Tauber  http://jtauber.com/
> journeyman of some   http://jtauber.com/blog/
>
>
>
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, I think I understand what you're getting at, given your comment
referring to the "unnecessary table and associated join".  I think you want
to be able to say "ManyToOneField" in Place and have it reach back into the
Photo model and insert a NULLable "place_id" column.  That's problematic for
several reasons:

   1. The Photo model is no longer self-contained.  You can't look at the
   model and infer the table layout.  So, for example, you can't just syncdb on
   the Photo model's application and get the table you want.  Without knowledge
   of other applications (potentially in other projects!) you don't know what
   the table will look like.
   2. It produces inelegant tables at best (I'm too lazy to confirm
   whether it actually violates any normalization rules).  If you have many
   models referring to Photo in this way, it will have equally many columns,
   most of which will be NULL in any case.

If you want it to work this way, I think it is best that you are explicit
about the presence of the foreign keys and code ForeignKey(x, null=True)
within the Photo model.  But if you want the "directionality" to go the way
you indicate, I do think it is correct and more elegant to have the
intermediate join table.

  -- Scott

On Tue, May 13, 2008 at 3:41 PM, Michael Burton <[EMAIL PROTECTED]> wrote:

>
> Sure.  OOM relationships can typically be broken down along two
> dimensions: cardinality and directionality.
>
> cardinality:  DIRECTIONALITY
> --
> One-to-one:   ONE-WAY, BI-WAY
> One-to-many:  ONE-WAY, BI-WAY
> Many-to-many: ONE-WAY, BI-WAY
>
>
> The cardinality is pretty obvious, it's just one-to-one, one-to-many,
> or many-to-many, as we'd all expect.  Django assumes that all
> relationships are bi-directional, meaning that if there's a
> relationship between A and B then you can access that relationship
> from A and you can also access it from B.
>
> However, in some cases (like the one I originally asked the question
> about), it's useful to have a one-way relationship, such that you can
> access B from A, but not the other way around.  In this case, the
> directionality would be one-way.
>
> I'm making up all the terminology here, but hopefully the idea comes
> across.  Django assumes bidirectionality[1], but it would be nice to
> be able to make uni-directional relationships for those cases, like
> Photo, where the photo can be owned by multiple different models in a
> one-to-many way.
>
> To keep the models clean my plan is to use your many-to-many
> suggestion, but it does result in an unnecessary table and associated
> join, which is a bummer but tolerable.
>
> Thanks again,
> Mike
>
> [1] From
> http://www.djangoproject.com/documentation/db-api/#how-are-the-backward-relationships-possible
> :
> "Other object-relational mappers require you to define relationships
> on both sides. The Django developers believe this is a violation of
> the DRY (Don't Repeat Yourself) principle, so Django only requires you
> to define the relationship on one end."
>
>
> On May 13, 12:03 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > Michael, can you elaborate on what you mean by "forcing bi-directional
> > relationships"?
> >
> > The ManyToManyField approach really is, I think, the "right" way to do
> it.
> > If you think about it, a hypothetical ManyToOneField in your case would
> work
> > almost exactly like the ManyToManyField.  The join table would be
> structured
> > exactly the same, except it would have an additional UNIQUE(photo_id)
> > qualifier.
> >
> >   -- Scott
> >
> >
> >
> > On Tue, May 13, 2008 at 2:56 PM, Michael Burton <[EMAIL PROTECTED]>
> wrote:
> >
> > > Thanks much, Scott.  They both seem a bit hacky, but it gives me
> > > something to work with anyway.
> >
> > > I recognize the motivation for forcing bi-directional relationships in
> > > Django was done to keep things DRY[1], but does anyone know if there's
> > > been any discussion about maybe relaxing this constraint?  Seems a
> > > little restrictive, and I don't think most other web frameworks go
> > > this route for that very reason...
> >
> > > Mike
> >
> > > [1]
> > >http://www.djangoproject.com/documentation/db-api/#how-are-the-backwa.
> ..
> >
> > > On May 13, 11:32 am, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > > > Michael, you have two alternatives:
> >
> > > >1. Create ManyToManyField fiel

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, can you elaborate on what you mean by "forcing bi-directional
relationships"?

The ManyToManyField approach really is, I think, the "right" way to do it.
If you think about it, a hypothetical ManyToOneField in your case would work
almost exactly like the ManyToManyField.  The join table would be structured
exactly the same, except it would have an additional UNIQUE(photo_id)
qualifier.

  -- Scott

On Tue, May 13, 2008 at 2:56 PM, Michael Burton <[EMAIL PROTECTED]> wrote:

>
> Thanks much, Scott.  They both seem a bit hacky, but it gives me
> something to work with anyway.
>
> I recognize the motivation for forcing bi-directional relationships in
> Django was done to keep things DRY[1], but does anyone know if there's
> been any discussion about maybe relaxing this constraint?  Seems a
> little restrictive, and I don't think most other web frameworks go
> this route for that very reason...
>
> Mike
>
> [1]
> http://www.djangoproject.com/documentation/db-api/#how-are-the-backward-relationships-possible
>
>
>
>
> On May 13, 11:32 am, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> > Michael, you have two alternatives:
> >
> >1. Create ManyToManyField fields in the UserProfile and Place models,
> >pointing to Photo.  "ManyToManyField" may seem a bit odd since you
> really
> >have a many-to-one relation, but it will work as you expect, creating
> a join
> >table connecting each pair of models.
> >2. Create two ForeignKey fields in Photo, one to UserProfile and one
> >to Photo, with null=True.  Yes, this is a bit ugly. :)
> >
> >   -- Scott
> >
> >
> >
> > On Tue, May 13, 2008 at 2:24 PM, Michael Burton <[EMAIL PROTECTED]>
> wrote:
> >
> > > I have some Places and I have some Users in my database.  I'd like to
> > > be able to associate some Photos with each.
> >
> > >  class Photo(models.Model):
> > ># a model that represents a photo
> >
> > >  class UserProfile(models.Model):
> > ># has a list of Photos
> >
> > >  class Place(models.Model):
> > ># has a list of Photos
> >
> > > Normally, if i were using another ORM framework, I would make my Place
> > > have a list of photos, and I'd make my UserProfile have a list of
> > > photos, and I'd leave my Photo model alone.  However, the Django way
> > > of doing things requires that I put a ForeignKey into my Photo model
> > > to establish the one-to-many.
> >
> > > The problem is, sometimes Photo's ForeignKey will point to a
> > > UserProfile and sometimes to an Place.  How can I have both my
> > > UserProfile and Place models point to Photos?
> >
> > > Thanks in advance,
> > > Mike
> >
> > --http://scott.andstuff.org/|http://truthadorned.org/<http://scott.andstuff.org/%7Chttp://truthadorned.org/>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, you have two alternatives:

   1. Create ManyToManyField fields in the UserProfile and Place models,
   pointing to Photo.  "ManyToManyField" may seem a bit odd since you really
   have a many-to-one relation, but it will work as you expect, creating a join
   table connecting each pair of models.
   2. Create two ForeignKey fields in Photo, one to UserProfile and one
   to Photo, with null=True.  Yes, this is a bit ugly. :)

  -- Scott

On Tue, May 13, 2008 at 2:24 PM, Michael Burton <[EMAIL PROTECTED]> wrote:

>
> I have some Places and I have some Users in my database.  I'd like to
> be able to associate some Photos with each.
>
>  class Photo(models.Model):
># a model that represents a photo
>
>  class UserProfile(models.Model):
># has a list of Photos
>
>  class Place(models.Model):
># has a list of Photos
>
>
> Normally, if i were using another ORM framework, I would make my Place
> have a list of photos, and I'd make my UserProfile have a list of
> photos, and I'd leave my Photo model alone.  However, the Django way
> of doing things requires that I put a ForeignKey into my Photo model
> to establish the one-to-many.
>
> The problem is, sometimes Photo's ForeignKey will point to a
> UserProfile and sometimes to an Place.  How can I have both my
> UserProfile and Place models point to Photos?
>
> Thanks in advance,
> Mike
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: response.write and memory, newbie question!

2008-05-12 Thread Scott Moonen
Andrew, it will build up its contents in memory.  Consider how an exception
thrown in your view will cause the response never to even be sent.

Your best bet if you want to do streaming is to pass an iterator to the
HttpResponse constructor.  Your iterator should yield strings to its caller.

  -- Scott

On Mon, May 12, 2008 at 12:16 PM, Andrew Smith <[EMAIL PROTECTED]>
wrote:

>
> Hello
>
> When I use response as a file-like object, by calling response.write
> or passing it to something which expects a file-like object, does it
> build up its contents in memory or stream them straight to the
> browser?
>
> TIA
>
> Andy
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

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



Re: one-to-many design question

2008-05-09 Thread Scott Moonen
Slight correction.  In your first example:

class Chapter(models.Model):
>book = models.ForeignKey(Chapter)
>

The parameter to ForeignKey should be book:

class Chapter(models.Model):
   book = models.ForeignKey(Book)

As mentioned earlier, you can locate a chapter's book as chapter.book, and
you can locate a book's chapters using book.chapter_set.all().

  -- Scott Moonen

On Fri, May 9, 2008 at 12:08 PM, Mike Chambers <[EMAIL PROTECTED]>
wrote:

>
> I am working on an app to host some books online. I cant figure out the
> best way to represent a one to many relationship.
>
> Basically, a Book has multiple Chapters, but a Chapter can only be in
> one book.
>
> Looking at the docs, this seems to be the way to represent this:
>
>
> --
> class Book(models.Model):
>
>
> class Chapter(models.Model):
>book = models.ForeignKey(Chapter)
> --
>
> Is that right? This seems a little counterintuitive to me, and something
> like this seems to make more sense:
>
>
> --
> class Book(models.Model):
>chapters = models.ManyToManyField(Chapter)
>
> class Chapter(models.Model):
> --
>
> Of course, that means that a chapter can be placed on multiple books.
>
> The second example, also seems to make it a little easier to work with
> Books, as I can do:
>
> Book.objects.all()
>
> and get the Chapters associated with each book.
>
> So, what is the "correct" way to model this relationship?
>
> Thanks for any input...
>
> mike
>
>
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: django_sessions table getting out of hand

2008-05-09 Thread Scott Moonen
See
http://www.djangoproject.com/documentation/sessions/#clearing-the-session-table

  -- Scott

On Fri, May 9, 2008 at 10:24 AM, Matt Davies <[EMAIL PROTECTED]> wrote:

> I got you Scott
>
> cron job it is
>
> I seem to remember Adrian putting a nippet up somewhere with the code
> in(laxz I know), anyone remember where it was?
>
>
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: How to modify contrib.auth models etc

2008-05-09 Thread Scott Moonen
Ok.  Sounds like you can probably get by with creating your own ancillary
GroupData model (for example) and associating it one-to-one with the Group
model.  I've done this in the past with User, creating my own UserData model
to hold some additional attributes, and it worked well for me.

  -- Scott

On Fri, May 9, 2008 at 10:14 AM, Marcin Gorczyński <[EMAIL PROTECTED]>
wrote:

>
> Well basicly I want the groups to have more data associeted with them
> - like a image filename, extracting the numer of users, one-to-one
> relations with a model in a news app and forum app, adding models like
> category like this category->groups, group and category moderators.
> Probarly I can get what I want from the user model by the profile
> model, personal messages to users (maybe that shuld be another app)
>
> Thanks
> >
>


-- 
http://scott.andstuff.org/  |  http://truthadorned.org/

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



Re: How to modify contrib.auth models etc

2008-05-09 Thread Scott Moonen

Hi Marcin.  Can you give some more detail on what specific additional
functionality you need?

It is possible that you can augment the existing models by creating
your own ancillary "UserData" and "GroupData" models, each with a
OneToOneField that relates directly to the auth.models.User and
auth.models.Group models, and each containing any additional data and
relations that you need.  With the appropriate edit_inline setting on
the OneToOneField you can even edit this data on the User/Group page
in the admin interface.  However, if you are looking to extend some of
the behavior of the existing models; e.g., stretching permissions to
do something new, then you might be better off creating your own
models.

  -- Scott Moonen

On May 9, 9:48 am, Marcin Gorczyński <[EMAIL PROTECTED]> wrote:
> Hello
>
> I have a problem to tackle - in my site I want to have groups that
> have assigned forums, news etc. The Django contrib.auth just aren`t
> enough (also I need a more custom user model). Anyone can please tell
> me a good way to come around those limits? I thought about coding my
> own user, group app but that would take some time and I`m searching
> for a easier way.
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django_sessions table getting out of hand

2008-05-09 Thread Scott Moonen

Hi Matt.  The reason folks don't prefer to do it within the
application code is because it introduces a delay into rendering pages
while the DELETE is executed -- even in cases where there is nothing
to delete.  By running the DELETE in a cron job you improve the
performance of your page loads.

  -- Scott Moonen

On May 9, 8:54 am, "Matt Davies" <[EMAIL PROTECTED]> wrote:
> Thanks for getting back to me Arien
>
> If that's what people are doing to sort it out then that's fine by me, I can
> write a cron job to run a script and everyone is happy.
>
> If anyone has a more elegant solution I'm all ears.
>
> I suppose I could overwrite sections of the middleware so that whenever a
> session is created it checks the table and bins the expired records then,
> but I don't want to edit the source code if I can help it, for obvious
> upgrading reasons.
>
> I could pull that middleware into my app to avoid the problem I've just
> mentioned, but see how messy it is getting already?
>
> Is there a reason for keeping records in the django_sessions table once
> they've expired?  There may be one that I don't know of.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---