On 6/6/07, Bryan Veloso <[EMAIL PROTECTED]> wrote:
>
> Alright, new problem for you guys. Here's an example model in an app
> called "scores", which contains all the scores for a particular
> player:
>
> # Baseball
> baseball                = models.PositiveIntegerField('Baseball Skill
> Level', blank=True, null=True, maxlength=4)
> # Bowling
> bowling                 = models.PositiveIntegerField('Bowling Skill
> Level', blank=True, null=True, maxlength=4)
> # Boxing
> boxing                  = models.PositiveIntegerField('Boxing Skill
> Level', blank=True, null=True, maxlength=4)
>
> (etc.)
>
> Now, right now all the scores are lumped within this model. My
> question comes in when trying to call these items in my views. Say if
> I want to gather all the baseball scores and sort them. What would the
> queryset call for that be?

It sounds like you're looking for a query like:

Score.objects.order_by('baseball')

That is, get all the Person objects, and sort them by the value of the
'baseball' score (

Score.objects.order_by('-baseball')

will return all the objects in reverse order.

However, it looks like your table is intended to be at least partially
sparse (i.e., every score  object doesn't have all the values). If
this is the case, you may want to exclude some data from the list of
objects:

Score.objects.filter(baseball__isnull=False).order_by('baseball')

will get all the objects that have a baseball score (i.e., the
baseball score _isn't_ None), and orders them by the value of the
baseball field.

Hope this helps,
Russ Magee %-)

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

Reply via email to