Answer the question
In order to leave comments, you need to log in
What is the correct way to link two model forms in Django?
Hello, I am learning django and I need to do the following: I have two models Seller and Goods, they are linked using ForeignKey, here is the code:
class Seller(models.Model):
title = models.CharField('Название магазина', max_length=255)
url = models.URLField('Ссылка на магазин')
internal_url = models.CharField('Внутренняя ссылка', max_length=255)
description = models.TextField('Описание', max_length=5000)
rate = models.IntegerField('Рейтинг', default=0)
publish_date = models.DateField('Дата добавления', auto_now_add=True)
display = models.BooleanField('Отображение на главной', default=False)
email = models.EmailField('E-Mail администратора', default='')
class Goods(models.Model):
seller = models.ForeignKey(Seller, on_delete=models.CASCADE)
name = models.CharField('Что вы продаёте?', max_length=255)
class SellerForm(ModelForm):
class Meta:
model = Seller
fields = ['title', 'url', 'description', 'email']
class GoodsForm(ModelForm):
class Meta:
model = Goods
fields = ['name']
Answer the question
In order to leave comments, you need to log in
Since these are just tags, it can be implemented using the django-taggit battery. Instead of the Goods model, add a TaggableManager to the Seller, and add a TagField from the same library to the form.
PS
Here is a small manual ilnurgi1.ru/docs/django/contrib/django-taggit.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question