2
私はDjango初心者です。私はこのアプリを試してみたいdjango-smart-selects。私は、管理サイトの「注文」フォームで適切な「顧客」を選択することにより、「顧客」アドレスが自動入力されるようにしたいと思います。Django django-smart-select:管理サイトにデータを追加中にTemplateSyntaxErrorを取得します
だから私は、次の
models.py今
from smart_selects.db_fields import ChainedForeignKey
from django.db import models
# Adress model
class Adresse (models.Model):
strasse = models.CharField(max_length=50)
plz = models.IntegerField(max_length=5)
ort = models.CharField(max_length=50)
def __unicode__(self):
return self.strasse
# Customer model
class Customer (models.Model):
name = models.CharField(max_length=50)
adresse = models.ForeignKey(Adresse)
def __unicode__(self):
return self.name
# Order model
class Order (models.Model):
name = models.CharField(max_length=50)
delivery_time = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
kunde = models.ForeignKey(Customer, related_name="Kunde")
adresse = ChainedForeignKey(
Customer,
chained_field="kunde",
chained_model_field="strasse",
show_all=False,
auto_choose=True
)
class Meta:
db_table = 'order'
ordering = ['-created_at']
def __unicode__(self):
return self.name
admin.py
from django.contrib import admin
from customer_order.test_app.models import Adresse, Customer, Order
class AdresseAdmin(admin.ModelAdmin):
list_display = ('strasse', 'plz', 'ort',)
class CustomerAdmin(admin.ModelAdmin):
list_display = ('name', 'adresse',)
list_per_page = 50
class OrdersAdmin(admin.ModelAdmin):
list_display = ('name', 'delivery_time', 'created_at', 'kunde', 'adresse',)
list_display_links = ('name',)
list_per_page = 50
ordering = ['-created_at']
admin.site.register(Adresse, AdresseAdmin)
admin.site.register(Customer, CustomerAdmin)
admin.site.register(Order, OrdersAdmin)
私が最初にエントリを追加したい定義されています管理者の追加ボタンを使用して "注文"テーブル、私は次のeを得たrror:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/test_app/order/add/
Exception Type: TemplateSyntaxError
Exception Value:
Caught an exception while rendering: Reverse for 'chained_filter' with arguments '()' and keyword arguments '{'field': 'strasse', 'app': 'test_app', 'model': 'Customer', 'value': '1'}' not found.
Original Traceback (most recent call last):
File "C:\Python25\lib\site-packages\django\template\debug.py", line 71, in render_node
result = node.render(context)
File "C:\Python25\lib\site-packages\django\template\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "C:\Python25\lib\site-packages\django\utils\encoding.py", line 71, in force_unicode
s = unicode(s)
File "C:\Python25\lib\site-packages\django\forms\forms.py", line 356, in __unicode__
return self.as_widget()
File "C:\Python25\lib\site-packages\django\forms\forms.py", line 391, in as_widget
return widget.render(name, data, attrs=attrs)
File "C:\Python25\lib\site-packages\django\contrib\admin\widgets.py", line 231, in render
output = [self.widget.render(name, value, *args, **kwargs)]
File "H:\customer_order\smart_selects\widgets.py", line 36, in render
url = "/".join(reverse("chained_filter", kwargs={'app':self.app_name,'model':self.model_name,'field':self.model_field,'value':"1"}).split("/")[:-2])
File "C:\Python25\lib\site-packages\django\core\urlresolvers.py", line 350, in reverse
*args, **kwargs)))
File "C:\Python25\lib\site-packages\django\core\urlresolvers.py", line 300, in reverse
"arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'chained_filter' with arguments '()' and keyword arguments '{'field': 'strasse', 'app': 'test_app', 'model': 'Customer', 'value': '1'}' not found.
Exception Location: C:\Python25\lib\site-packages\django\template\debug.py in render_node, line 81
Python Executable: C:\Python25\python.exe
Python Version: 2.5.0
ありがとうございました。目は2つより良いです:-) – saeed