你可能想使用django.contrib.auth
,它已经提供了User
模型,所以你要到模型写入store additional user information,而不是定义新的User
模型。 Django模型(通常)表示数据库表,每个属性表示一个数据库字段。您可以定义模型及其关系,并且Django提供了一个很好的数据库访问API。您通常不会“存储帐户对象的集合”,您可以创建另一个模型并使用字段来描述模型之间的关系。
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
age = models.IntegerField()
class Account(models.Model):
user_profile = models.ForeignKey('UserProfile')
然后你会使用Django的API与您的模型工作:
profile = User.objects.get(id=1).get_profile() # get user's profile
profile.account_set.all() # get all accounts associated with user's profile
acct = Account() # create a new account
profile.account_set.add(acct) # add a new account to the user's profile
Django's tutorial是一个良好的开端,如果你想使用Django对于这个项目,你需要的一些概念事情如何完成。首先可能是learn python的好主意。
您是否试图将基于Java的应用程序转换为Django项目?我不确定你在做什么,但你应该从这里开始:https://docs.djangoproject.com/en/1.3/intro/tutorial01/ – zeekay 2011-06-17 06:27:49
其实我已经有了基于java的UML类,现在我必须在Python中编码。我可以管理其他东西,但我只想知道是否可以将对象集合存储在python类中 – 2011-06-17 06:29:47
也许你应该从这里开始:http://docs.python.org/tutorial/ – zeekay 2011-06-17 06:34:12