Herkese selamlar,
Bir projemde takıldım arkadaşlar yardımcı olur musunuz?
Senaryom şu,
Bir ürün modelim mevcut. Bu modelin içerisinde de ürün miktarı var.
Bir model daha oluşturup satın alma sürecini gerçekleştirmek ve ürünleri envantere eklemek istiyorum.
Örnek model.py aşağıdaki gibidir.
class Product(models.Model):
product_code = models.CharField(max_length=50)
product_name = models.CharField(max_length=100)
product_price = models.DecimalField(decimal_places=2, max_digits=10)
product_tax = models.PositiveIntegerField()
product_category = models.ForeignKey('ProductCategory', verbose_name='Product category', on_delete=models.CASCADE)
product_brand = models.ForeignKey('ProductBrand', verbose_name='Product brand', on_delete=models.CASCADE)
product_description = models.TextField()
product_create_date = models.DateTimeField(auto_now_add=True)
product_update_date = models.DateTimeField(auto_now=True)
product_amount = models.IntegerField()
class Meta:
verbose_name_plural = "Product"
def __str__(self):
return self.product_name
def get_absolute_url(self):
return "/products/{}".format(self.id)
class ProductAmount(models.Model):
product = models.ForeignKey(Product, blank=True, on_delete=models.CASCADE)
product_amount = models.IntegerField()