Anyone figure out a sort algorithm to do this please? list = DateTimeDuration.objects.all().filter(date=now).order_by('resource','start') max_hours = 8
this produces Resource – start – duration – user-name Item - 9 - 4 - T Test Item- 10 - 4 - Alpha Bravo Item - 14 - 2 - Herod First what I need is to sort it so that it outputs like this: Item - 9 - 4 - T Test Item - 14 - 2 - Herod First Item - 10 - 4 - Alpha Bravo The parameters are: There are 8 hours in a day (max_hours = 8) the list of objects need to be sorted in such a way that if 2 or more objects combined duration is less than 8 then they need to be sorted in order of start time but if the start time of another object is the same or the start time is within the duration of an object then it must be shuffled backwards As an adder: Each resource has a finite number so is there a way to utilise the max number of resources within a resource so that we know how many resources are unused? MODEL for info class Resource(models.Model): resource = models.CharField(max_length=30) resource_capacity = models.IntegerField() seating = models.IntegerField() def __unicode__(self): return self.resource class User(models.Model): name = models.CharField(max_length=200) email = models.CharField(max_length=100, null=True, blank=True) tel = models.CharField(max_length=100, null=True, blank=True) class DateTimeDuration(models.Model): user = models.ForeignKey(User) resource = models.ForeignKey(Resource) date = models.DateField() start = models.IntegerField(max_length=5, help_text="whole number like 9, 10, 11, 12, 13, 14, 15, 16, 17") hours = models.IntegerField(max_length=2, help_text="Number of hours as a whole number like 3") class Meta: verbose_name_plural = 'Booking Date-Time-Duration' ordering = ('date',) Anyone point me in the right direction please? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1a514440-ac50-4354-b220-b16fc32ca9ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.