我想计算一下用户上传的文件数量。
我添加了signals.py
from django.dispatch import Signal
upload_completed = Signal(providing_args=['upload'])
和summary.py
from django.dispatch import receiver
from .signals import upload_completed
@receiver(charge_completed)
def increment_total_uploads(sender, total, **kwargs):
total_u += total
我的项目。
我的视图上载
@login_required
def upload(request):
# Handle file upload
user = request.user
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile=request.FILES['docfile'])
newdoc.uploaded_by = request.user.profile
upload_completed.send(sender=self.__class__, 'upload')
#send signal to summary
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('upload'))
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the upload page
documents = Document.objects.all()
# Render list page with the documents and the form
return render(request,'upload.html',{'documents': documents, 'form': form})
这种努力不起作用。我
upload_completed.send(sender=self.__class__, 'upload')
^
SyntaxError: positional argument follows keyword argument
我找到信号的例子
testing-django-signals
from .signals import charge_completed
@classmethod
def process_charge(cls, total):
# Process chargeâ¦
if success:
charge_completed.send_robust(
sender=cls,
total=total,
)
但在我看来,classmethod在我的情况下是行不通的
如何解决我的方法?