[Django]-Prepopulate slug field from Foreign Key in Django

3👍

If you check the docs (http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields) it does state that you can’t reference a foreign key field.

Looking at you design would this not work better:

class BaseModel(models.Model):
    title = models.CharField(max_length=256)
    slug = models.SlugField()

class Issue(BaseModel):
    number = models.IntegerField(help_text="Do not include the '#'.")

class ComicBookSeries(BaseModel):
    issues = models.ForeignKey(Issue)

You need to declare the classes in that order!

Hope that helps!

Leave a comment