Hi all,

I'm building an e-commerce system and at the moment working on making the
products easily searchable.  But when I use a __range lookup, in some cases
it returns a 404 as if there is no data that matches that criteria, and
there is data that matches that criteria.  Using the "Logging" middleware
discussed a few days ago I have the SQL being stored, and if I copy/paste
that exact SQL into my query analyzer and run it (after adding single quotes
around the text lookup) it returns the two rows (in the case of the first
SQL statement below) that match the search just fine.  But django can't see
them.  (Running trunk, revision 4185)

Here's the SQL it's using:

SELECT
`products_productattribute`.`id`,`products_productattribute`.`product_id`,`products_productattribute`.`product_attribute_choice_id`,`products_productattribute`.`value`
FROM `products_productattribute` INNER JOIN
`products_productattributechoice` AS
`products_productattribute__product_attribute_choice` ON
`products_productattribute`.`product_attribute_choice_id` =
`products_productattribute__product_attribute_choice`.`id` WHERE
(`products_productattribute`.`value` BETWEEN 6 AND 10 AND
`products_productattribute__product_attribute_choice`.`slug` = 'weight')

I'm searching through product attributes to find anything that weighs
between 6 and 10 lbs.  The same query for items between 0 and 6 lbs

SELECT
`products_productattribute`.`id`,`products_productattribute`.`product_id`,`products_productattribute`.`product_attribute_choice_id`,`products_productattribute`.`value`
FROM `products_productattribute` INNER JOIN
`products_productattributechoice` AS
`products_productattribute__product_attribute_choice` ON
`products_productattribute`.`product_attribute_choice_id` =
`products_productattribute__product_attribute_choice`.`id` WHERE
(`products_productattribute`.`value` BETWEEN 0 AND 6 AND
`products_productattribute__product_attribute_choice`.`slug` = 'weight')

returns items, just as it should.

The urls.py entry catching it:


(r'^shopbyrange/(?P<product_attribute_choice>[-\w]+)/(?P<valuefrom>[-\w]+)-(?P<valueto>[-\w]+)/$',
'project.products.views.searchbyattributerange'),

The project.products.views.searchbyattributerange view:

def searchbyattributerange(request, product_attribute_choice, valuefrom,
valueto):
   product_list = ProductAttribute.objects.filter
(value__range=(valuefrom,valueto),product_attribute_choice__slug__exact=product_attribute_choice)
   return object_list(request, queryset=product_list)

And the related entries from models.py:

class ProductAttributeChoice(models.Model):
   name = models.CharField(maxlength=64)
   slug = models.SlugField(prepopulate_from=('name',),unique=True)
   sites = models.ManyToManyField(Site,filter_interface=True)
   def __str__(self):
      return self.name
   class Admin:
      pass

class ProductAttribute(models.Model):
   product = models.ForeignKey(Product,edit_inline=models.TABULAR
,num_in_admin=5,num_extra_on_change=5)
   product_attribute_choice = models.ForeignKey
(ProductAttributeChoice,core=True)
   value = models.CharField(maxlength=64,core=True)

I hope I haven't left anything out.  If there's anything else I can provide,
let me know.


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