D
D
David Winter2020-11-29 10:14:47
Django
David Winter, 2020-11-29 10:14:47

Adding multiple categories to one item?

There is a code, how can I do this?

THE CODE:

from django.db import models

# Create your models here.

class Category(models.Model):
    name_of_category = models.CharField(max_length=200)
    
    def __str__(self):
        return self.name_of_category
    
    
class Good(models.Model):
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    date_of_relise = models.DateField('Relise')
    price = models.FloatField(default=0)
    
    def __str__(self):
        return self.name, self.description

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-11-29
@Dcruel

ManyToManyField

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question