gpt4 book ai didi

django - 查看我的 Django 模型 - 需要很多建议

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:33 24 4
gpt4 key购买 nike

我正在收集各种信息源来建立一个人的文件。一旦我这样做了,我想灵活地以不同的方式看待一个人。我在 Django 中没有太多经验,所以我想对我的模型进行批评(温和)。诚然,即使我编写了这个代码,我也在考虑冗余(反对 DRY),但我想知道其他人的想法。 FWIW - 这些数据是拉取的而不是创建的 - 所以也许我不应该保留所有数据但删除数据似乎很糟糕..

具体来说,我想知道 ManyToMany 的使用是否合适,或者您是否只是 KISS 并将每个条目保留为自己的条目而没有任何 ManyToMany 业务。从长远来看,我认为 KISS 会使它的更新变得简单(一个基本的 for 循环),但是在能够查询一个人(比如基于 location_description 或 job_function)方面是否存在权衡。无论如何,我将不胜感激。

class Person(models.Model):

"""This simply builds a notes user"""

aliases = models.ManyToManyField(Aliases) #Hmm this is list..
assistant = models.CharField(max_length = 255, blank = True)
cell_phone = models.CharField(max_lenth = 16, blank = True)
city = models.ManyToManyField(City)
country = models.ManyToManyField(County)
department = models.ManyToManyField(Department)
departmeht_number = models.ManyToManyField(Department_Number)
division_code = models.ManyToManyField(Division_Code)
email = models.EmailField(max_length = 50)
functional_area = models.ManyToManyField(Functional_Area)
# jpeg = models.
job_classification = models.ManyToManyField(Job_Classification)
job_classification_code = models.ManyToManyField(Job_Classification_Code)
last_name = models.CharField(max_length = 255)
location_description = models.ManyToManyField(Location_Description)
location_path = models.ManyToManyField(Location_Path)
mail_address = models.CharField(max_length = 255, blank = True)
mail_domain = models.ManyToManyField(Mail_Domain)
mail_file = models.CharField(max_length = 255, blank = True)
mail_server = models.ManyToManyField(Mail_Server)
match_pct = models.CharField(max_lenth = 6)
name = models.CharField(max_length = 255)
name_reverse = models.CharField(max_length = 255)
nickname = models.CharField(max_length = 32)
notes_url = models.URLField()
# object_class = models.
office_phone = models.CharField(max_length = 255, blank = True)
other_phone = models.CharField(max_length = 255, blank = True)
position = models.ManyToManyField(Position)
section = models.ManyToManyField(Section)
section_code = models.ManyToManyField(SectionCode)
shift = models.ManyToManyField(Shift)
state = models.ManyToManyFiedl(State)
supervisor = models.ManyToManyField(Supervisor)
supervisor_reverse = models.ManyToManyField(Supervisor_reverse)
uid = models.CharField(max_length = 128)

def __unicode__(self):
return str(self.name)

最佳答案

__unicode__ 应该返回 unicode

def __unicode__(self):
return u'%s' %self.name

Django 为完整地址提供了一个电子邮件字段:

mail = models.EmailField()

我认为,地址模型可能是有意义的。一个人可以有多个地址(工作、家庭……)

编辑

我刚刚看到,您正在使用 emailfield。

这是做什么用的:

mail_address = models.CharField(max_length = 255, blank = True)
mail_domain = models.ManyToManyField(Mail_Domain)
mail_file = models.CharField(max_length = 255, blank = True)
mail_server = models.ManyToManyField(Mail_Server)

?

编辑

您不必一直使用 ManyToManyFields。查看 ForeignKey、OneToOneField 和通用框架

关于django - 查看我的 Django 模型 - 需要很多建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1829489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com