这里我有两个模型。在这些模型中,我想amount_to_pay在Ledger模型中实现动态值。例如,对于这两个模型,我有两种不同的形式,并且如果用户选择payment_option来自ledger模型的模型并给出一些值,则可以节省费用形式amount_to_pay那么如果仅该字段ledger.id并且与该字段expense.payment_option_id相同,amount_to_pay则应将账本模型中的值替换为该值。我该怎么办?
models.py
class Expense(models.Model):
pay_from = models.CharField(max_length=200)
payment_option = models.ForeignKey('Ledger', on_delete=models.CASCADE)
amount_to_pay = models.IntegerField(default=0)
expense_date = models.DateField(default=datetime.date.today)
expense_type = models.ForeignKey(ExpenseType, on_delete=models.CASCADE)
note = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
slug = AutoSlugField(unique_with='id', populate_from='expense_type')
def get_amount_to_pay(self):
return self.amount_to_pay
class Ledger(models.Model):
name = models.CharField(max_length=200)
account_number = models.CharField(max_length=250, unique=True)
account_type = models.CharField(max_length=200)
opening_balance = models.IntegerField(default=0)
amount_to_pay = models.IntegerField(default=0, blank=True, null=True)
current_balance = models.IntegerField(default=0, blank=True, null=True)
created …Run Code Online (Sandbox Code Playgroud) 这是带有vue.js的单页应用程序,它做了一些简单的计算,我正在尝试在django中实现此计算,但它没有给我想要的结果。在django中实现之前,此vue.js代码做得很完美。在这里,我使vue.js中的数组成为动态数组,这也只向我显示了产品的图像,但没有完美显示product.name,product.sell_price并且@click.prevent="addToCart(product)"此函数没有执行任何操作?我该如何解决?
vue.js
<script src="{% static 'js/vue.js' %}"></script>
<script type="text/javascript" src="{% static '/js/vue-resource.js' %}"></script>
<script>
new Vue({
el: '#posApp',
data: {
total: 0,
discount: 0,
products: [
{% for product in products %}
{
"id": {{product.id}},
"name": "{{product.name}}",
"image": "/media/{{product.image}}",
"price": {{product.sell_price}}
},
{% endfor %}
],
cart: [],
search: ""
},
methods: {
addToCart: function(product){
var found = false;
for (var i = 0; i < this.cart.length; i++){
if (this.cart[i].id === product.id){
this.cart[i].quantity++;
found …Run Code Online (Sandbox Code Playgroud)