gpt4 book ai didi

python /Django : Is it wise to use "Item" as a class name in Python (in Django in this case)?

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

我正在创建这个:

# models.py

class Item(models.Model):
sku = models.CharField(max_length=20)

class Attribute(models.Model):
item = models.ForeignKey(Item, related_name='items')

这会导致 Python 中的命名冲突吗?喜欢:

# views.py

some_object.items.create(sku='123abc')

# Is there a place / way that this could cause errors, like:
# AttributeError: Bound method 'items' has no attribute "create"
# Since items() on a dict-like object could be a method to return a list,
# and Django could add support for .items() on a queryset right?

如果这是个坏主意,我可以更改名称。

最佳答案

它看起来确实有点笼统,但也不过是“属性”而已。如果可能的话,我会根据应用程序给它一个前缀。

关于 python /Django : Is it wise to use "Item" as a class name in Python (in Django in this case)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2145282/

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