Slug字段工作正常,但现在我不想在网站管理中的表单中进行autocoplete。 slu field场与田野naslov相连。 当我在字段naslov上写字但用连字符和小写字母时,我不会在字段slug上显示该文本。
models.py
from django.db import models
class Question(models.Model):
naslov = models.CharField(max_length=200)
slug = models.SlugField()
opis = models.CharField(max_length=200)
datum_objave = models.DateTimeField('date published')
opsirnije_text = models.TextField(max_length=20000)
def __str__(self):
return self.naslov
def spremi(self):
if not self.id:
self.slug = slugify(self.naslov)
super(test, self).save()
def was_published_recently(self):
return self.datum_objave >= timezone.now() - datetime.timedelta(days=1)
admin.py
from django.contrib import admin
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
question_fields = {"slug": ("naslov",)}
admin.site.register(Question, QuestionAdmin)
答案 0 :(得分:1)
from .models import Question
class QuestionAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("naslov",)}
admin.site.register(Question, QuestionAdmin)