2017-07-29 57 views
1

在Django中我很新,在管理員用西里爾符號使用search_fields時出現UnicodeEncodeError。搜索ascii符號正常工作。我應該尋找什麼?在Django中使用search_fields時出現UnicodeEncodeError admin

Exception Type: UnicodeEncodeError at /admin/persons/person/ 
Exception Value: 'ascii' codec can't encode characters in position 0-11: ordinal not in range(128) 

models.py

class Person(GenericModel, DatePeriodMixin): 
    last_name = models.CharField(_(u'фамилия'), max_length=255) 
    first_name = models.CharField(_(u'имя'), max_length=255, blank=True) 
    patronymic = models.CharField(_(u'отчество'), max_length=255, blank=True) 

    class Meta: 
     verbose_name = _('персоналия') 
     verbose_name_plural = _('персоналии') 
     ordering = ['last_name', 'first_name', 'patronymic'] 

    def __unicode__(self): 
     return u'{} {} {}'.format(
      self.last_name, 
      self.first_name, 
      self.patronymic).rstrip() 

    def get_absolute_url(self): 
     return reverse('persons:detail', kwargs={'pk': self.pk}) 

admin.py

@admin.register(Person) 
class PersonAdmin(admin.ModelAdmin): 
    list_display = ('last_name', 'first_name', 'patronymic') 
    search_fields = ['last_name'] 
    list_filter = ('profession') 
    filter_horizontal = ('organizations', 'profession') 

    def save_model(self, request, obj, form, change): 
     obj.editor = request.user 
     obj.save() 
+0

如果您還可以提供拋出異常的代碼 -/admin/persons/person/- 它將提供更好的機會讓某人能夠向您顯示錯誤所在。 – PTD

+0

@PTD更新了我的問題 – algeron

回答

相關問題