我的老工人问题通过PIP安装Pinax和它安装在站点包。所有的应用程序都在那里。我们自己的应用程序在我们的Django项目结构中。有关扩展任何Django应用程序
我想通过将create_user
的is_active
标志切换为False来修改Pinax的帐户应用程序。目前,该应用使其成为True
。我也想添加额外的功能create_user
或任何我想要做的功能。
from pinax.account import forms
class MyCustomizeForm(forms.SignupForm):
def create_user(....):
super(....)
// additional...
也许这样? 但是,这不需要我至少执行两次与数据库交互的提交事务吗?
是不是最好?另外,这样做是否需要我在我的Django项目中更改其他任何内容(用户注册的方式,它使用的视图...使用什么形式)?
目前,我有一个应用程序住在我的Django项目设对付account
应用程序的扩展/定制。我无法将站点包提交到VCS ....我的意思是......我不应该在那里做任何更改。
谢谢。
Pinax帐户/ models.py
class Account(models.Model):
...
def its_own_method(...)
# this is in the same indentation level as class Account
def create_account(sender, instance=None, **kwargs):
if instance is None:
return
account, created = Account.objects.get_or_create(user=instance)
post_save.connect(create_account, sender=User)
感谢。你是说自定义动作会在'save()'实际被调用之前执行,还是在它完成之前执行直到最后一行? – User007 2012-07-11 18:25:33
pre_save信号将为您提供即将保存的模型实例。您有机会在该信号处理程序的上下文中对其进行修改。您不需要在该处理程序中调用保存。它即将被保存,并且一旦它完成了所有pre_save信号。 – jdi 2012-07-11 18:58:31
谢谢。但是执行'pre_save.connect(make_inactive,sender = User)'意味着只要'User'模型正在保存,它就会触发'make_inactive'函数。我用Pinax账户的信号更新了我的帖子。我该怎么做呢? – User007 2012-07-11 19:28:54