在django admin中,这是在添加对象时为相关模型创建实例的方式。

时间:2018-09-06 00:53:06

标签: django

我有以下型号: 产品,类别,利润率,成本,价格

class Product(models.Model):
    category = models.ForeignKey(Category, ...)

class Category(models.Model):
    formula = models.CharField(...)
#formula is goint to be something like "(cost1+fixedmargin1)*percentmargin+cost2

class Margin(models.Model):
    category = models.ForeignKey(Category..)        
    margin = models.DecimalField(...)

class Cost(models.Model):
    product = models.ForeignKey(Product...)
    cost_name = models.CharField(...)
    cost_value = models.DecimalField(...)

class Pricing(models.Model):
    product = models.OneToOneField(Product...)
    price = models.DecimalField(...)

    def calculate(self):
        #collect all margins, costs and calculate the pricing formula from Category and save self.price = calculated price

在我的管理员中,     Class CostInline(admin.StackedInline):

class MarginInline(admin.StackedInline):

class ProductAdmin(admin.ModelAdmin):
    inlines = (CostInline, )

class CategoryAdmin(admin.ModelAdmin):
    inlines = (MarginInline, )

当我尝试添加成本的产品时出现问题, 这些成本不会节省,而价格计算方法不会获得成本,而只会获得公式和利润(它们都在“类别”中预先设置)

当我在具有大量内联的admin中添加产品时,是否存在,我可以添加和修复那些相关字段而无需先添加/保存产品?

0 个答案:

没有答案