到目前为止,我已经扩展了对象工具块并创建了自己的自定义,但还没有采取行动。
{% extends "admin/change_form.html" %}
{% block object-tools-items %}
<li>
<a href="<your-action-url>"class="historylink">ComputeDepreciation</a>
</li>
{{ block.super }}
{% endblock %}
这是我的模型。py有两个模型。资产折旧外键
# models.py
class Asset(models.Model):
gross_value = models.FloatField()
salvage_value = models.FloatField()
life = models.IntegerField()
class Depreciation(models.Model):
asset_id = models.ForeignKey('Asset',on_delete=models.SET_NULL,
null=True,)
depreciation_value = models.CharField(verbose_name='Depreciation
Value',max_length=255,)
annual_depreciation = models.CharField(verbose_name='Annual
Depreciation',max_length=255,)
这是我的admin.py
# admin.py
class AssetDepreciationInline(admin.TabularInline):
model = Depreciation
extra = 0
class AssetAdmin(admin.ModelAdmin):
inlines = [AssetDepreciationInline]
我想使用自定义对象工具填充“折旧”字段。请帮助,谢谢。