N
N
njkit2021-05-27 22:50:20
Django
njkit, 2021-05-27 22:50:20

Why, when building a database, and creating keys, do the arrows in the diagram go the other way?

On sqlite, I create a database, when prescribing keys, on the diagram, the plates are connected, but in the wrong direction.
One brand may correspond to several models.
Is it supposed to be like this or am I doing something wrong?
PyCharm.

models.py------------------------------

class sprMarka(models.Model):
    naimmarka = models.CharField('Наименование марки тс', max_length=100)


    def __str__(self):
        return self.naimmarka, self.naimmodel

    def get_absolute_url(self):
        return f'/gruzi/{self.id}'

    class Meta:
        verbose_name = 'Марка тс'
        verbose_name_plural = 'Марки тс'

class sprModel(models.Model):
    naimmodel = models.CharField('Наименование модели тс', max_length=100)
    naimmarka = models.ForeignKey(sprMarka, on_delete=models.CASCADE, default='')


    def __str__(self):
        return self.naimmodel

    def get_absolute_url(self):
        return f'/gruzi/{self.id}'

    class Meta:
        verbose_name = 'Модель тс'
        verbose_name_plural = 'Модели тс'

60aff7a1b3e4e317714222.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maksam07, 2021-05-28
@maksam07

If I understand correctly, then everything is correct:
Any string (id) from sprMarka can be attached to one line in sprModel
And sprMarka itself is not attached to anything
Personally, it was difficult for me to understand such a small code, corny because of some identical or similar variables. I looked at the code 10 times and tried to understand where the differences are

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question