문제

I'm trying to save a Persian slug for this model:

class Category(models.Model):
    name = models.CharField('name', max_length=100)
    slug = models.SlugField('slug', unique=True)
    description = models.TextField('description')

    class Meta:
        verbose_name = 'category'
        verbose_name_plural = 'categories'

    @permalink
    def get_absolute_url(self):
        return ('category_detail', None, {
            'slug': self.slug
        })

    def __unicode__(self):
        return u'%s' % self.name

But Django does not save the page and complaint that:

Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens

I also tried to use this save method instead

    def save(self, *args, **kwargs):
      self.name = slugify_unicode(self.name)
      super(Category, self).save(*args, **kwargs)

but it did not solve the problem. So I got stock on this and appreciate your help to resolve this.

도움이 되었습니까?

해결책

You can't. Slug fields can only contain ASCII letters, numbers, dashses and underlines.

If you must use non-ASCII chars in a slug-like field, you can use a normal CharField and add a db_index = True to it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top