如何在ModelMultipleChoiceField中显示我的模型我有models.py
# Модель заказа
class ProductsSet(models.Model):
# Название набора
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="ID")
name = models.CharField(max_length=200)
products_set = models.ManyToManyField('ProductsInstance', related_name='sets')
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
created_date = models.DateField(null=True, blank=True)
class ProductsInstance(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
help_text="Unique ID")
product = models.ForeignKey('Products', on_delete=models.RESTRICT, null=True)
admin.py
@admin.register(ProductsInstance)
class ProductsInstanceAdmin(admin.ModelAdmin):
list_display = ('product', 'price_for_client', 'borrower', 'coeff')
list_filter = ('status','borrower',)
fieldsets = (
(None, {
'fields': ('product', 'coeff', 'price_for_client', 'id')
}),
('Availability', {
'fields': ('status', 'borrower')
}),
)
@admin.register(ProductsSet)
class ProductsSetAdmin(admin.ModelAdmin):
list_display = ('name', 'borrower', 'created_date', 'status', 'total_amount')
fields = ['id', 'name', 'products_set', 'created_date', 'borrower', 'status', 'total_amount']
list_filter = ['borrower','created_date','status']
我现在看起来像什么enter image description here
这就是我想要的enter image description here
2条答案
按热度按时间bzzcjhmw1#
以下是我的解决方案:
bkhjykvo2#
在**
filter_horizontal
**属性[Django-doc]中列出关系:您也可以使用**
filter_vertical
**属性[Django-doc],其中两个框显示在彼此的上下。