# Extending an abstract class: Cannot use defined field as prepopulated\_fields

**URL:** <https://forum.djangoproject.com/t/extending-an-abstract-class-cannot-use-defined-field-as-prepopulated-fields/25256>\
**Category:** The Admin\
**Created:** [November 12, 2023, 6:44pm UTC](https://forum.djangoproject.com/t/extending-an-abstract-class-cannot-use-defined-field-as-prepopulated-fields/25256 "2023-11-12T18:44:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kontur](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kontur/32/17028_2.png) [@kontur](https://forum.djangoproject.com/u/kontur)\
**Post date:** [November 12, 2023, 6:44pm UTC](https://forum.djangoproject.com/t/extending-an-abstract-class-cannot-use-defined-field-as-prepopulated-fields/25256/1 "2023-11-12T18:44:03Z")

</div>

I was trying to refactor my models to reuse the code for defining and saving slugs like so:

```auto
class SlugMixin:
    slug = models.SlugField(null=True, blank=True)

    def save(self, *args, **kwargs):
        # Take the __str__ output and slugify it
        self.slug = slugify(self)
        super().save(*args, **kwargs)

    class Meta:
        abstract = True

...

class SomeModel(SlugMixin, models.Model):
    name = models.CharField(...

   def __str__ (self):
       return self.name

    ...

```

And in my admin.py I’m trying to:

```auto
class SomeModelAdmin:
    prepopulated_fields = {"slug": ("name",)}

```

However, I’m getting this error:

> \<class ‘someapp.admin.SomeModelAdmin’\>: (admin.E027) The value of ‘prepopulated\_fields’ refers to ‘slug’, which is not a field of ‘someapp.SomeModel’.

If I move the `slug` field definition into my model the code works as intended. I can still use the `SlugMixin` and its `save` method from the mixin, but defining the actual `slug` field definition right in the mixin makes the admin code reject it with the error. Am I doing something wrong or is this an actual bug?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 13, 2023, 11:39am UTC](https://forum.djangoproject.com/t/extending-an-abstract-class-cannot-use-defined-field-as-prepopulated-fields/25256/2 "2023-11-13T11:39:53Z")

</div>

A parent abstract model class is not a mixin. Your child class should only inherit from SlugMixin and not the combination of SlugMixin and Model.

---

<div class="post-metadata">

**Author:** ![kontur](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kontur/32/17028_2.png) [@kontur](https://forum.djangoproject.com/u/kontur)\
**Post date:** [November 14, 2023, 12:41pm UTC](https://forum.djangoproject.com/t/extending-an-abstract-class-cannot-use-defined-field-as-prepopulated-fields/25256/3 "2023-11-14T12:41:48Z")

</div>

Ah, thank you! Thank makes sense. Works when inheriting directly. I was refactoring the “mixin” with just the save method but forgot about the model definitions with the multiple inheritance.
