A good start would be to put that sql in get_min_rent into a queryset... I
it's queryset.select(....). I'm not sure if you'll then be able to
order_by('min_rent') though...
Ben

On 10/10/2007, Dan <[EMAIL PROTECTED]> wrote:
>
>
> Hi
>
> I am trying to make an advanced search page where a user can list
> guest-houses based on several different criteria. As there can be many
> rooms in a house each with different availability and rent prices i am
> having problems constructing a filter for this.
>
> Models:
>
> class Property(models.Model):
>    name = models.CharField(max_length=30, verbose_name=_('Property
> Name'))
>    property_type = models.CharField(max_length=2,
> choices=PROPERTY_CHOICES)
>    ............
>    def get_available_rooms(self):
>         return Room.objects.filter(property=self,
> available=True).count()
>
>    def is_room_available(self):
>         if self.get_available_rooms():
>             return True
>         else:
>             return False
>
>     def get_min_rent(self):
>         from django.db import connection
>         cursor = connection.cursor()
>         cursor.execute("SELECT min(DISTINCT rent) FROM property_room
> AS r WHERE r.property_id = %s", [self.id])
>         return cursor.fetchone()[0]
>
> class Room(models.Model):
>     property = models.ForeignKey(Property, verbose_name=_('Property'))
>     rent = models.DecimalField(max_digits=9, decimal_places=2)
>     available = models.BooleanField()
>     .........
>
> So basically in the view i would like to do a filter on Property with
> the critera: property_type, min_rent, max_rent, is_room_available etc
> but this throws up an error as min_rent, max_rent, is_room_available
> are not fields in the database, I looked at the custom model managers
> and they seems to work but just for one custom criteria at a time.
>
> Could someone please recommend a good way to solve this issue so i can
> produce a queryset with all these search criteria, thanks.
>
> -Dan
>
>
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+6281317958862

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