你们有这个模式:
class Category(models.Model):
node_id = models.IntegerField(primary_key = True)
type_id = models.IntegerField(max_length = 20)
parent_id = models.IntegerField(max_length = 20)
sort_order = models.IntegerField(max_length = 20)
name = models.CharField(max_length = 45)
lft = models.IntegerField(max_length = 20)
rgt = models.IntegerField(max_length = 20)
depth = models.IntegerField(max_length = 20)
added_on = models.DateTimeField(auto_now = True)
updated_on = models.DateTimeField(auto_now = True)
status = models.IntegerField(max_length = 20)
node = models.ForeignKey(Category_info, verbose_name = Category_info , to_field = node_id
The important part is the foreignkey. When I try:
Category.objects.filter(type_id = 15, parent_id = offset, status = 1)
我发现的错误比重的类别,因为本应退还不止一个类别。 但是,我要过滤另一个领域的成果,即类型(从第二个模型中)
这里是:
class Category_info(models.Model):
objtree_label_id = models.AutoField(primary_key = True)
node_id = models.IntegerField(unique = True)
language_id = models.IntegerField()
label = models.CharField(max_length = 255)
type_id = models.IntegerField()
从1到5年不等。 我完全试图只取得一种结果,即补贴类型为1。
这里我想的是:
SELECT c.*, ci.*
FROM category c
JOIN category_info ci ON (c.node_id = ci.node_id)
WHERE c.type_id = 15 AND c.parent_id = 50 AND ci.type_id = 1
任何帮助都是GREATLY。
关于