Re: Better Query Set Use

2008-06-05 Thread Chris Hartjes
On 6/4/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> You can use Q objects to preform OR queries.  So it would look like
> this:
>
> from django.db.models import Q
> games = Game.objects.filter(Q(home_team=searchTeam) |
>
> Q(away_team=searchTeam)).filter(game_date__range(date_form.cleaned_data['startDate'],
> date_form.cleaned_data['endData'])).order_by('games_date',
> 'start_time')
>
>
>
Alex, thanks very much!  Worked like a charm.

-- 
Chris Hartjes

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



Better Query Set Use

2008-06-04 Thread Chris Hartjes
Hi there. Long-time PHP developer now getting into Python and Django.

I'm using the latest version of Django from SVN and are building a query
that does the following:

Give me all the games where
homeTeam = searchTeam OR awayTeam = searchTeam
AND game_date is between start_date and end_date
ORDER BY game_date, start_date.

Here's the code for it

games = Game.objects.filter(home_team=searchTeam,
game_date__range=(date_form.cleaned_data['startDate'],
date_form.cleaned_data['endDate'])).order_by('game_date', 'start_time') |
Game.objects.filter(away_team=searchTeam,
game_date__range=(date_form.cleaned_data['startDate'],
date_form.cleaned_data['endDate'])).order_by('game_date', 'start_time')

Now, it gets me the desired results but it just looks ugly.  I'm wondering
if there is a better way to do this?  I spent some time googling around for
answers but didn't find anything that could help me.

Thanks in advance.

-- 
Chris Hartjes

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Need some slightly advanced routing help

2008-05-04 Thread Chris Hartjes
On Sun, May 4, 2008 at 9:21 PM, Steven Armstrong <[EMAIL PROTECTED]> wrote:

>
> Hi Chris
>
> or, if you want it more specific:
>
> (r'^(?P\w+)/(?P\d{4}-\d{2}-\d{2})/$', 'myview'),
>
>
> Personally I'd go with the last example in this case.
>

That one worked perfectly.  I had a brain cramp about the dashes in the date
format.  Thanks!

-- 
Chris Hartjes

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



Need some slightly advanced routing help

2008-05-04 Thread Chris Hartjes
I've been trying to do something that I *think* should be simple,
but apparently is not.  Or, the more likely answer is that I am missing
something pretty obvious.  I spent some time googling around for the answer
but didn't find what I was looking for.  So here goes.
I'm building a web service to return sports game information.  I have three
routes:

/ -- shows a help page on how to use the web service
//
///

 is the name of a team in lowercase, could be 'yankees' or
'red+sox'
the date fields are formatted as -MM-DD.  Now, I've looked at both the
Django book and the online Django documentation to try and figure out the
correct way to get the routes to work.  Here's what's in my urls.py file:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^(?P\w+)/(?P\w+)/$', 'rallyhat.ws.views.team_by_date'),
(r'^(?P\w+)/(?P\w+)/(?P\w+)/$',
'rallyhat.ws.views.team_by_date_range'),
(r'^/?$', 'rallyhat.ws.views.index'),
)

Now, my index page route works just fine, but the two others won't work.

When I try /yankees/2008-08-15 I get this:

*

Using the URLconf defined in rallyhat.urls, Django tried these URL patterns,
in this order:


   1. ^(?P\w+)/(?P\w+)/$

   2. ^(?P\w+)/(?P\w+)/(?P\w+)/$

   3. ^/?$


The current URL, /yankees/2008-05-18/, didn't match any of these.
*

I *know* it's something dumb, but I just can't see it.  Any help would be
greatly appreciated.

-- 
Chris Hartjes

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

2008-04-23 Thread Chris Hartjes
On Wed, Apr 23, 2008 at 6:04 AM, bcurtu <[EMAIL PROTECTED]> wrote:

>
>
> But, turning back to my question... Can you tell these sites with
> thousands or hundreds of thousands hits per minute? Ok, let's leave
> apart their stats... Any big name on the internet? slashdot? twitter
> is RoR...
>

I think you should worry about building something first, then worry about
whether or not it can handle huge amounts of traffic.  If you are getting
thousands or hundreds of thousands of hits per minute then (a) you are doing
better than 99.999% of the web applications out there and (b) will be
creating custom solutions to your particular scaling problems.  Twitter is
built on Rails, but has been heavily modified to meet their specific needs.
 It wouldn't surprise me if Pownce was the same way.

Before people get on my case, understand I'm not advocating doing no
planning at all in terms of thinking about scalability.  I'm advocating
actually building something simple and to open standards as to make it
easier to scale out your app when the time comes.

On this topic, any good tutorials on handling query caching and output
caching in Django?  Those are two things I would build into any sort of web
app right from the beginning.

-- 
Chris Hartjes

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



More Advanced Forms Help

2008-04-05 Thread Chris Hartjes
Thanks to all who made suggestions before.  Now I have another problem I
have been unable to find a way to solve in Django.  Here's the scenario:
I have the variable games, which contains (oddly enough) games
I have the variable stadium_forms, which contains a form for each game that
displays a check box

I want to do something like this

{% for game in games %}
(display info about game)
 (display form in stadium_forms that belongs to the game) 
{% endfor %}

For every item in 'games' there is a corresponding item in 'stadium_forms'

I found this page to be helpful in figuring out how to build the
stadium_forms variable:

http://www.pointy-stick.com/blog/2008/01/06/django-tip-complex-forms/

Any tips on how to make this work would be greatly appreciated.

-- 
Chris Hartjes

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

2008-04-02 Thread Chris Hartjes
On Wed, Apr 2, 2008 at 3:28 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:

>
> If your goal is to edit multiple items read this:
>
> http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/
>

Alex,

That's pretty much what I'm looking for.  Thanks!

-- 
Chris Hartjes

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



Advanced Form Questions

2008-04-01 Thread Chris Hartjes
Hi there.  I'm a newbie at Python but have lots of experience with PHP and
MVC frameworks in general.  The question I have is on the proper Django way
to solve a problem.
I want to create a form where you can enter multiple teams and multiple
dates in order to find out where and when they are playing a baseball game.
 So, in the abstract you'd have stuff like this:

Team 1  
Team 2  
Team 3  

So, my question becomes this:

1) how do I get Django to generate those form elements for me so I don't
have to do it by hand
2) how do I get Django to process those values when they come in.

I've been using the Django Book site and the Django Project site to help me,
and they've been great but I can't find much about how to solve this
problem.  Maybe my Google fu is not strong enough.

I'm already creating my own Form object

from django import newforms as forms
class SearchForm(forms.Form) :
   team = forms.CharField()
   gameDate = forms.DateTimeField()

and already understand to a certain extent how to process the incoming POST
data

def search_results(request):
if request.method == 'POST':
form = SearchForm(request.POST)
 if form.is_valid():
team = form.cleaned_data['team']
gameDate = form.cleaned_data['gameDate']
team = Team.objects.get(name=team)
games = Game.objects.order_by('game_date').filter(home_team=team,
game_date=gameDate) | Game.objects.order_by('game_date').filter(away_team=team,
game_date=gameDate)
 if games.count <= 30:
showResults = True
else:
showResults = False
 else:
games = 'Hoopa'
 return render_to_response('search/results.html', {'games': games,
'showResults': showResults})
else:
return HttpResponseRedirect('index/index.html')


Any help would be greatly appreciated. Tips on doing things the Django way,
or even just the Python way are good as well.  I'm trying hard to not write
PHP-style code in Python.  :)

-- 
Chris Hartjes

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