mardi 5 mai 2015

How to filter for a single object based on multiple instances of another object?

I'm trying to create a query to find renters that match at least one of a set of floorplans and need help writing the query.

The Renter model

class RenterProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, null=True, blank=True)
    name = models.CharField(max_length=120)
    desired_location = models.CharField(max_length=120)
    move_in_date = models.DateField(null=True, blank=True, help_text='Use mm/dd/yyyy format')
    coordinates =models.CharField(max_length=120, blank=True, null=True)
    lat = models.CharField(max_length=120, blank=True, null=True)
    lng = models.CharField(max_length=120, blank=True, null=True)
    price = models.IntegerField(max_length=120, blank=True, null=True)
    numbers = (('0','0'),('1','1'),('2','2'),('3','3'),('4','4'),('5','5'),('6+','6+'),)    
    beds = models.CharField(max_length=120, blank=True, null=True, choices=numbers)
    baths = models.CharField(max_length=120, blank=True, null=True, choices=numbers)

The FloorPlan Model

class FloorPlan(models.Model):
    property_name = models.ForeignKey(Property)
    floor_plan_name = models.CharField(max_length=120, blank=True, null=True)
    numbers = (('0','0'),('1','1'),('2','2'),('3','3'),('4','4'),('5','5'),('6+','6+'),)
    bedrooms = models.CharField(max_length=120, blank=True, null=True, choices=numbers)
    bathrooms = models.CharField(max_length=120, blank=True, null=True, choices=numbers)
    sqft = models.IntegerField(max_length=120, blank=True, null=True)
    min_price = models.IntegerField(max_length=120, blank=True, null=True)
    max_price = models.IntegerField(max_length=120, blank=True, null=True)
    availability = models.DateField(null=True, blank=True, help_text='Use mm/dd/yyyy format')
    image = models.ImageField(upload_to='floor_plans/', null=True, blank=True)    

Aucun commentaire:

Enregistrer un commentaire