I'm just starting out with django and need some help with how to
perform custom queries.  The query I want to do is basically this:

SELECT num_volunteers, num_boxes, (num_boxes * 216) as meals,
(num_boxes/num_volunteers) as box_per_person FROM shifts WHERE site =
%s AND date BETWEEN %s and %s

I've got my models setup like this in models.py

class Location(models.Model):
        name = models.CharField(maxlength=255)
        state = models.CharField(maxlength=2)
        def __str__(self):
                return self.name + ", " + self.state

        class Admin:
                list_display = ('name', 'state')



class Shift(models.Model):
        site = models.ForeignKey(Location)
        date = models.DateTimeField('shift date')
        num_volunteers = models.IntegerField()
        num_boxes = models.IntegerField()

        def __str__(self):
                return str(self.site.name)+" - "+str(self.date)

        class Admin:
                list_display = ('site', str('date'), str('num_boxes'),
str('num_volunteers'))
                list_filter = ['site', 'date']
                date_hierarchy = 'date'

I can find some mention of custom sql and custom managers in the docs,
but am completely confused at where the code goes and how to use it.
Could someone please try to explain this to me.

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

Reply via email to