【发布时间】:2018-10-17 11:36:07
【问题描述】:
我的问题是我有两个模型,一个是 product 和 taxproduct。在这里我提到了一对多的关系,我已经将产品 ID 映射到 taxproduct 中。在这个 component.ts 中 Save_user 是一个产品服务。 Save_tax 是一种税收产品。首先,我想插入产品,我想将该 id 与 TAxproduct 映射。
component.ts
createNewProduct(productForm: NgForm) {
this.productService.save_user(productForm.value)
.subscribe(response => {
const toast_parameter = this.notificationService.getToast('success', 'New Product', 'Inserted Successfully');
this.toastConfig = toast_parameter.config;
this.toasterService.popAsync(toast_parameter.toast);
},
error => {
const toast_parameter = this.notificationService.getToast('error', 'New Product', 'Error Occurred!!');
this.toastConfig = toast_parameter.config;
this.toasterService.popAsync(toast_parameter.toast);
});
for (let i = 0; i < this.contacts.length; i++) {
console.log(this.contacts[i])
this.productService.save_tax(JSON.stringify(this.contacts[i] )).subscribe(response => {
const toast_parameter = this.notificationService.getToast('success', 'New Product', 'Inserted Successfully');
this.toastConfig = toast_parameter.config;
this.toasterService.popAsync(toast_parameter.toast);
},
error => {
const toast_parameter = this.notificationService.getToast('error', 'New Product', 'Error Occurred!!');
this.toastConfig = toast_parameter.config;
this.toasterService.popAsync(toast_parameter.toast);
});
}
}
Model.py
class Product(models.Model):
image = models.ImageField(upload_to='myphoto/%Y/%m/%d/', null=True, max_length=255)
pro_name = models.CharField(max_length=25)
description = models.CharField(max_length=150)
category = models.ForeignKey(Category,on_delete=models.CASCADE)
sales = models.CharField(max_length=25)
cost = models.CharField(max_length=25)
taxable = models.BooleanField(default=False, blank=True)
tax_details= models.CharField(max_length=250)
type_units = models.ForeignKey(Units, on_delete=models.CASCADE)
hsn = models.CharField(max_length=10)
class Taxproduct(models.Model):
tax_name = models.CharField(max_length=50)
tax_percentage = models.CharField(max_length=3)
product_id = models.ForeignKey(Product, on_delete=models.CASCADE)
【问题讨论】:
标签: angular angular2-forms angular2-services angular2-directives