Many-To-Many Relationships: To Define A Many-To-Many Relationship, Use
Many-To-Many Relationships: To Define A Many-To-Many Relationship, Use
Example: "models.py"
from django.db import models
class Publisher(models.Model):
idno = models.AutoField(primary_key=True)
name = models.CharField(max_length=50)
class Article(models.Model):
idno = models.AutoField(primary_key=True)
name = models.CharField(max_length=50)
pub = models.ManyToManyField(Publisher)
app/forms.py
from django import forms
from .models import Publisher,Article
class PublisherForm(forms.ModelForm):
class Meta:
model = Publisher
fields = "__all__"
labels = {"name":"NAME"}
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = "__all__"
labels = {"name":"NAME","pub":"PUBLISHER"}
app/models.py
from django.db import models
class BiryaniTypes(models.Model):
no = models.AutoField(primary_key=True)
type = models.CharField(max_length=30)
class Biryanis(models.Model):
no = models.AutoField(primary_key=True)
type_of_biryani =
models.ForeignKey(BiryaniTypes,on_delete=models.CASCADE)
name = models.CharField(max_length=30)