0
我的模型:Django的自動創建模型
class Urunler(AnaModel):
adi = models.CharField(max_length=128, verbose_name="Ürün Adı")
aciklama = models.TextField(verbose_name="Açıklama")
kategori = models.ForeignKey(Kategoriler, verbose_name="Kategori", related_name="urunler", null=True)
agirlik = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="Ağırlık", default=Decimal(1))
birim = models.CharField(max_length=2, choices=BIRIMLER, default="kg")
class Stok(AnaModel):
adi = models.ForeignKey(Urunler, related_name="stok", verbose_name="Ürün Adı")
marka = models.CharField(max_length=256, verbose_name="Marka/Firma")
stok_giris = models.DateTimeField(verbose_name="Stok Giriş Tarihi")
uretim_tarihi = models.DateField(verbose_name="Üretim Tarihi", blank=True, null=True)
sk_tarihi = models.DateField(verbose_name="Son Kullanma Tarihi", blank=True, null=True)
irsaliye_no = models.PositiveIntegerField(max_length=32, verbose_name="İrsaliye No", blank=True)
fatura_no = models.PositiveIntegerField(max_length=32, verbose_name="Fatura No", blank=True)
adet = models.PositiveIntegerField(default=Decimal(1))
aciklama = models.TextField(verbose_name="Açıklama", null=True)
class StokCikis(AnaModel):
adi = models.ForeignKey(Urunler, related_name="stok_cikis", verbose_name="Ürün Adı")
stok_cikis = models.DateTimeField(verbose_name="Stok Çıkış", blank=True, null=True, auto_now=True)
teslim_alan = models.CharField(verbose_name="Teslim Alan", max_length=128, null=True, blank=True)
aciklama = models.TextField(verbose_name="Açıklama", null=True, blank=True)
adet = models.PositiveIntegerField(default=Decimal(0)
當 「Urunler」 模型創建產品。可以自動生成「庫存」和「StockCikis」模型嗎?我想用默認值自動創建它。
是的,這可以在模型層或視圖層 –
做我的新呢。你能幫助我嗎? –
我建議您瀏覽整個django教程https://docs.djangoproject.com/en/1.10/intro/tutorial01/ –