[Python] Creating an object of a class whose field is a set of objects of another class

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    In the Django model lets create a class, eg Ingredients:

    class IngredientsClass(models.Model):
    name = models.CharField('Name', max_length=50, default='')
    package_price = models.FloatField()
    package_amount = models.FloatField()
    supplier = models.ForeignKey(SupplierClass)
    price = models.FloatField()


    Now lets make some product from the ingredients

    class DishClass(models.Model):
    name = models.CharField('Name', max_length=50, default='')
    price = models.FloatField()
    ingredients = models.***???***


    And here is a problem... In the field ingredients of an DishClass object can be different amount of ingredients from one to thousand.

    How do I need to set up the field ingredients?

    Continue reading...

Compartilhe esta Página