B
B
bituke2020-10-25 20:19:07
Django
bituke, 2020-10-25 20:19:07

How to define a relationship object for a model in django?

There are two models:

from django.db import models

class Category_item(models.Model):
  name_category = models.CharField('Название категории', max_length=100)

class Item(models.Model):
  name = models.CharField('Название пункта', max_length=100)
  description = models.TextField('Описание пункта')
  Category_item = models.ForeignKey(Category_item, on_delete=models.CASCADE, null=True, blank=True)

Let's say, given that Category_item has the blank=True attribute, I haven't defined the link, and now I need to define it without the admin panel, through some function.
I will be grateful for any answer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bituke, 2020-10-25
@bituke

https://djbook.ru/rel3.0/ref/models/relations.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question