我創建這個:Python/Django:在Python中使用「Item」作爲類名是明智的嗎(在這種情況下,在Django中)?
# 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?
如果這是一個壞主意,我可以改變名稱。
「有點通用」?我會說它太模糊以至於毫無意義。當然,有比「項目」和「屬性」更清晰準確的名稱。 – 2010-01-27 11:15:56
「屬性」不在應用程序中。這只是爲了舉例。有問題的班是「項目」。如果有人在他們的商店中有「物品」,那麼它就不適用於「無意義」這個詞語了,是嗎?可能使用這個術語的原因是,「項目」在電子商務世界中比「產品」更普遍,雖然「產品」不一定能夠推斷混淆的可能性,但我保持公開介意命名約定。 – orokusaki 2010-01-27 17:52:10