第1部分我的数据表与 obj 迭代一起使用,但我正在转向DRF-datatables .. 虽然我的示例站点运行没有问题,但我的实际实现却让我大吃一惊。基本上,我整个周末都在显示一个似乎正在加载数据的表格(因为分页显示了正确的信息),但我的行都是空白的:https: //i.stack.imgur.com/19LPp.png然后我尝试在脚本中添加“列”部分,这会破坏整个表格:https://i.stack.imgur.com/1Ln4A.png如果我将 ajax 调用更改为"ajax": "/api/entry/?format=datatables",然后我得到最密切的工作表:https://i.stack.imgur.com/KvAtK.png - 但是问题仍然是行是空的,如果我添加列,那么一切都会中断。我哪里错了?我也没有收到任何错误消息,因此很难调试数据表。也许第 2 部分..我是否需要使用 DRF 数据表?我的最终目标是能够选择多行,然后编辑所有这些条目的交易。最终目标示例选择3个交易单击表格顶部某处的下拉菜单从该下拉列表中选择 Trade PK单击“保存”表格显示最新数据条目列表.htmlSerializers.pyclass EntrySerializer(serializers.ModelSerializer): class Meta: model = Entry fields = '__all__'Views.pyclass EntryViewSet(viewsets.ModelViewSet): """ API endpoint that allows groups to be viewed or edited. """ queryset = Entry.objects.all() serializer_class = EntrySerializer permission_classes = [permissions.IsAdminUser] filter_backends = (DjangoFilterBackend, OrderingFilter,)models.pyclass Entry(models.Model): ENTRY = 'entry' EXIT = 'exit' ENTRY_TYPE_CHOICES = [ (ENTRY, 'Entry'), (EXIT, 'Exit'), # (DIVIDEND_RECEIVED, 'Dividend Received'), # (DIVIDEND_SOLD, 'Dividend Sold'), ] class Meta: verbose_name = "Entry" verbose_name_plural = "Entries" trade = models.ForeignKey(Trade, on_delete=models.CASCADE, null=True, blank=True) date = models.DateTimeField(null=True, blank=True, default=datetime.datetime.now) amount = models.FloatField(null=True) price = models.FloatField(null=True) fee = models.FloatField(null=True, blank=True) entry_type = models.CharField(max_length=5, choices=ENTRY_TYPE_CHOICES, default=ENTRY) reg_fee = models.FloatField(null=True, blank=True) transaction_id = models.CharField(max_length=100, null=True, blank=True) symbol = models.ForeignKey(Symbol, on_delete=models.SET_NULL, blank=True, null=True) created_by = models.ForeignKey(User, null=True, blank=True, editable=False, on_delete=models.CASCADE)
添加回答
举报
0/150
提交
取消