Answer the question
In order to leave comments, you need to log in
Django. What is the best way to organize connections?
I am designing a database of equipment. There was a question of the correct organization of communications between models.
At the moment the code is as follows:
class Person(models.Model):
fullname = models.CharField(max_length=30)
#shop_accounts = models.ManyToManyField('ShopAccount', blank=True)
#stuff = models.ManyToManyField('Staff', blank=True)
def __str__(self):
return str(self.fullname)
class Shop(models.Model):
name = models.CharField(max_length=30)
url = models.CharField(max_length=100)
#accounts?
#persons?
def __str__(self):
return str(self.name)
class ShopAccount(models.Model):
login = models.CharField(max_length=30)
password = models.CharField(max_length=100)
person = models.ForeignKey(Person, on_delete=models.CASCADE)#on_delete=models.SET(Person)
shop = models.ForeignKey(Shop, on_delete=models.CASCADE)
def __str__(self):
return str(self.login)
class Stuff(models.Model):
name = models.CharField(max_length=30)
person = models.ForeignKey(Person, on_delete=models.CASCADE)#on_delete=models.SET(Person)
shop = models.ForeignKey(Shop, on_delete=models.CASCADE)
shop_account = models.ForeignKey(ShopAccount, on_delete=models.CASCADE)
comment = models.CharField(max_length=140, blank=True)
#here will be additional attributes
def __str__(self):
return str(self.name)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question