How can I organize the structure of entering the city/restaurant tables of the Django database?

Good day! I have a plan for the database structure.

An example is in the figure below.

For example, I have - all coffee shops - within one region - state or several regions.

In one city there are several cafes. In total, there can be 200 cafes and 10 cities.

The problem is how to enter data on cafes in the database tables.

And also change them if necessary. Enter data through forms.

Each cafe also has the following parameters - address, Internet page, profitability, income, number of staff, i.e. data belonging to one cafe. As well as staff and menu.

I think to first enter the cities in which there will be cafes. And then enter the names of the cafes.

And even later other parameters through other forms.

How can I make it so that at the second stage only the name, address is entered and then successively filled with other data?

How can I organize the structure of entering the city / restaurant tables of the Django database?

from django.db import models

# Create your models here.

class CityCafe (models.Model):
    city = models.CharField(verbose_name="City")


class ObjectCafe (models.Model):
    name = models.TextField(verbose_name="Cafe Name")
    name_city = models.ForeignKey(CityCafe)


class BaseParametrCafe (models.Model):
   # type_object = models.Choices 
   # type_working = models.Choices
    value_budget = models.FloatField

    name_object = models.OneToOneField(ObjectCafe, null=False, on_delete=models.CASCADE) 


from django import forms
from models import *


class FormCites (forms.ModelForm):

    class Meta:
        model = CityCafe
        fields = "__all__"


class FormObjects (forms.ModelForm):

    class Meta:
        model = ObjectCafe
        fields = "__all__"


class FormObjectsParametr (forms.ModelForm):

    class Meta:
        model = BaseParametrCafe
        fields = "__all__"



from django.shortcuts import render

from models import *

from forms import *


def form_cites_view (request):
    form = FormCites(request POST or None)
    if form.is_valid():
        post = form.save()
        post.save()
    return render(request, "form_1.html", {"form": form})

# Create your views here.

enter image description here

enter image description here

Вернуться на верх