0

モデルの値を、最大の注文値を持つ他のオブジェクトからのインクリーム値として*pre_init*注文したいと思います。私はこのような関数を書きました:

@receiver(pre_init, sender=Category)
def get_order(instance, **kwargs):    
    previous = Category.objects.all().order_by('-order')[0].order
    instance.order = previous + 1

しかし、管理パネルを実行すると、次のようなエラーが発生します。

Environment:


Request Method: GET Request URL: http://127.0.0.1:8000/admin/catalog/category/add/

Django Version: 1.5 Python Version: 2.7.2 Installed Applications: ('django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.sites',  'django.contrib.messages',  'django.contrib.staticfiles',  'django.contrib.flatpages',  'django.contrib.admin',  'utils',  'menu',  'contact',  'mediamanager',  'mptt',  'catalog') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware',  'django.middleware.locale.LocaleMiddleware',  'django.middleware.common.CommonMiddleware',  'django.contrib.auth.middleware.AuthenticationMiddleware',  'django.contrib.messages.middleware.MessageMiddleware',  'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs) File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in wrapper
  367.                 return self.admin_site.admin_view(view)(*args, **kwargs) File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  91.                     response = view_func(request, *args, **kwargs) File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in
_wrapped_view_func
  89.         response = view_func(request, *args, **kwargs) File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
  202.             return view(request, *args, **kwargs) File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs) File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  91.                     response = view_func(request, *args, **kwargs) File "C:\Python27\lib\site-packages\django\utils\decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2) File "C:\Python27\lib\site-packages\django\db\transaction.py" in inner
  208.                 return func(*args, **kwargs) File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in add_view
  971.             form = ModelForm(initial=initial) File "C:\Python27\lib\site-packages\django\forms\models.py" in __init__
  235.             self.instance = opts.model() File "C:\Python27\lib\site-packages\django\db\models\base.py" in __init__
  318.         signals.pre_init.send(sender=self.__class__, args=args, kwargs=kwargs) File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py" in send
  167.             response = receiver(signal=self, sender=sender, **named)

Exception Type: TypeError at /admin/catalog/category/add/ Exception Value: get_order() takes exactly 1 argument (0 given)

誰かがそれを修正する方法を知っていますか?または、pre_initシグナル関数をどのように見る必要がありますか?

4

1 に答える 1