Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

prepopulated fields in django not working properly

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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',)}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading