Home > Enterprise >  prepopulated fields in django not working properly
prepopulated fields in django not working properly

Time:12-16

class Theblog(models.Model):
    blog_image=models.ImageField(upload_to="home/images")
    blog_title=models.CharField(max_length=150)
    slug=models.SlugField(max_length=200)
    blog_description=models.CharField(max_length=200,default="Adsoptimiser")
    blog_body=RichTextField(blank=True,null=True)
    blog_date=models.DateTimeField()
    author=models.CharField(max_length=35,default="Sunil Kumar")
    blog_meta_keywords=models.TextField(default=" ")
    blog_meta_description=models.CharField(max_length=1000,default=" ")


class BlogAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('blog_title',)}
    list_display = ('blog_title','blog_date')
admin.site.register(metaTag)
admin.site.register(Theblog,BlogAdmin)

i want to prepulate the slug as the value of the title how to do it i have searchand get to see some ways i try to impliment but nothing is working for me please point out my mistake why this is happening

CodePudding user response:

Try this:

from django.contrib import admin

@admin.register(TheBlog)
class BlogAdmin(admin.ModelAdmin):
    list_display = ['blog_title','blog_date']
    prepopulated_fields = {'slug': ('blog_title',)}
  • Related