解释MySQL数据库模式的JSON代码



我对JSON完全陌生,想了解如何解释以下代码。基本上,我要求我的数据库为我提供数据库模式,这就是他给我的。我了解SQL,并希望创建它的模式的可视化表示。谁能简化一下。

class Vendor(models.Model):
AUTH_CHOICES = tuple(itertools.chain.from_iterable([(
('KEY', 'KEY'),
('PASSWORD', 'PASSWORD'),
('CUSTOM', 'CUSTOM'),
)]))
name = models.CharField(max_length=32, db_index=True, unique=True)
label = models.CharField(max_length=256, null=True, blank=True)
authentication_type = models.CharField(max_length=32, choices=AUTH_CHOICES, default='KEY')
authentication_inputs = jsonfield.JSONField(null=True, blank=True, default={},
dump_kwargs={'cls': JSONEncoder, 'indent': None,
'separators': (',', ':')})
tags = models.TextField(null=True, blank=True)
categories = models.TextField(null=True, blank=True)
is_hidden = models.BooleanField(default=False)
in_house = models.BooleanField(default=False)
feature = models.ForeignKey(Feature, related_name='vendor_features', null=True, on_delete=models.SET_NULL)
has_multiple_keys = models.BooleanField(default=False)
def __str__(self):
return self.label or self.name
class VendorApi(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.SET_NULL, null=True, related_name='apis')
name = models.CharField(max_length=32, db_index=True, unique=True)
label = models.CharField(max_length=256, null=True, blank=True)
plugin = models.CharField(max_length=64, null=True, blank=True)
def __str__(self):
return self.label or self.name
class VendorApiField(models.Model):
GROUP_CHOICES = tuple(itertools.chain.from_iterable([(
('COMPANY', 'COMPANY'),
('PERSON', 'PERSON'),
)]))
TYPE_CHOICES = tuple(itertools.chain.from_iterable([(
('STRING', 'STRING'),
('INTEGER', 'INTEGER'),
('FLOAT', 'FLOAT'),
('CURRENCY', 'CURRENCY'),
('DATETIME', 'DATETIME'),
('OBJECT', 'OBJECT'),
('ARRAY', 'ARRAY'),
('URL', 'URL'),
)]))
vendor_api = models.ForeignKey('VendorApi', related_name='fields', on_delete=models.CASCADE)
name = models.CharField(max_length=64, db_index=True, unique=False)
label = models.CharField(max_length=256, null=True, blank=True)
type = models.CharField(max_length=32, choices=TYPE_CHOICES, default='STRING')
example = models.CharField(max_length=256, null=True, blank=True)
description = models.CharField(max_length=256, null=True, blank=True)
rl_api_field = models.CharField(max_length=64, null=True, blank=True)
group = models.CharField(max_length=32, choices=GROUP_CHOICES, default='COMPANY')
class Meta:
unique_together = ('vendor_api', 'name', 'rl_api_field') ```

从业主的评论和问题中我可以理解。您只需要了解模型是如何连接的。让我给你解释一下。

1.) Vendor is a Model which is connected to another model named feature via foreign key relation(i.e one to many relationship)
2.) Vendor Api connects to Vendor Model via the same foreign key relation as above.
3.) Vendor ApiField connects to VendorApi model via foreign key relation.
To summarise:
Feature <-- Vendor <-- VendorApi <-- VendorApiField

其中<——表示通过外键的关系。(即一对多关系)在sql

最新更新