Django Admin:多对多模型过滤器,另一种方式
我一直坚持使用 django 的管理功能。
如何使用管理员的 list_filter 来处理来自 toppingsAdmin 的披萨?
For example, I have these models,
class Topping(models.Model):
# ...
class Pizza(models.Model):
# ...
toppings = models.ManyToManyField(Topping)
From PizzaAdmin, I can call list_filter = ('toppings',)
但是,我如何从toppingsAdmin 中调用披萨。似乎 list_filter = ('pizzas',)
不起作用,因为它在 Topping 模型中没有将其作为变量。
谢谢
I'm stuck on using django's admin feature.
How do I use admin's list_filter for the pizza from toppingsAdmin?
For example, I have these models,
class Topping(models.Model):
# ...
class Pizza(models.Model):
# ...
toppings = models.ManyToManyField(Topping)
From PizzaAdmin, I can call list_filter = ('toppings',)
But, How do I call pizzas from toppingsAdmin. Seems like list_filter = ('pizzas',)
does not work, because it doesn't have it as variable inside the Topping model.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 lated_name 添加到您的披萨模型中的配料字段:
现在您可以在 list_filter 中使用“披萨”
Add related_name to your toppings field in Pizza model:
Now you can use the 'pizzas' in the list_filter