0
src/
|-- grouping
| |-- __init__.py
| `-- models.py
|
`-- products
|-- __init__.py
`-- models.py
分組/ models.py訪問產品中的單個部門查詢集在ChainedForeignKey
from django.db import models
class Category(models.Model):
title = models.CharField(max_length=120)
class ProductDivisions(models.Model):
categories = models.ForeignKey(Category)
產品/ models.py
from django.db import models
class Product(models.Model):
Pdt_category = models.ForeignKey(Category)
Pdt_division = ChainedForeignKey(ProductDivisions,
chained_field="Pdt_category",
chained_model_field="category",
show_all=False,
auto_choose=True,
sort=True)
我試過,但它不生產任何東西,我想獲得特定產品的特定產品
產品/ Views.py
def division(request, slug=None):
single_div= get_object_or_404(ProductDivisions, slug=slug)
products = Product.objects.filter(Pdt_division=single_div)