我想从我的电子钱包中生成一个新的收信地址。为此,我创建了一个celery任务,该任务应将管理调用命令数据的输出保存到用户模型字段“ acc_btc_addr”。
但是以某种方式我猜我的任务有问题,我不知道如何从视图中调用task.py?任何想法
tasks.py
@app.task
def allocate_new_btc_address():
new_address = management.call_command('electrum', 'createnewaddress')
try:
user = User.objects.update_or_create(acc_btc_addr=new_address)
user.save()
logger.info("New BTC address has been allocated to the users account")
print(new_address)
except Exception as e:
print(e)
views.py
def wallet_deposit_gen_new_addr(request, pk=None):
if pk:
user = get_user_model.objects.get(pk=pk)
if request.method == 'POST':
....
else:
user = request.user
args = {'user': user}
return render(request, 'MyProject/wallet_deposit.html', args)
models.py
class User(AbstractBaseUser):
user = models.CharField(verbose_name='Username', max_length=20, unique=True)
bio = models.TextField(verbose_name='Bio', blank=True, null=True, max_length=2500)
acc_btc_addr = models.CharField(blank=True, null=True, max_length=35)
...