How can I link multiple Django model tables as if they were one when entering data?
Good morning! I am a bit new to Django.
I wanted to ask about the relationships between Django model tables. I have several Django model tables.
They should all belong to the same correspondence - a row from one table - is respectively related to a row from another table. That a row from one model table is also and, respectively, a row from another model table - they belong to and characterize one object. This is how I split one large table into several.
How can I make the tables related and - so that when filling in only one form through the Django model form - other related tables are also automatically filled in.
How can I form a single QuerySet or DataFrame from these several respectively related model tables.
How can I automatically send data not only to one table but also to others when sending data from the Django model form, which are related to several Django model tables as if they were one when entering data?
How can I link multiple Django model tables as if they were one when entering data?
class MyModel(models.Model):
id = models.AutoField(primary_key=True) # Auto-incrementing integer
uuid = models.UUIDField(default=uuid.uuid4)
name = models.CharField(max_length=255)
class MyModel(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
name = models.CharField(max_length=255)
from django import forms
class InputForm(forms.Form):
first_name = forms.CharField(max_length = 200)
last_name = forms.CharField(max_length = 200)
roll_number = forms.IntegerField(
help_text = "Enter 6 digit roll number"
)
password = forms.CharField(widget = forms.PasswordInput())
from django.shortcuts import render
from .forms import InputForm
# Create your views here.
def home_view(request):
context ={}
context['form']= InputForm()
return render(request, "home.html", context)
<form action = "" method = "post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit">
</form>