#Abstract Class Admin Settings
26 messages ยท Page 1 of 1 (latest)
I don't think you need to do anything special to have those fields show up.
From experimentation and Googling, if you have a field with auto_now or auto_now_add they won't show up in the admin because the system treats fields with those attributes as having blank=True which means they won't show up in the admin
ah ok that has nothing to do with the base class, then
just add the field name to the list_display attribute in the admin class
class Base(models.Model):
created_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class Question(Base):
question_text = models.CharField(max_length=200, db_comment="I hold questions")
...
I can't create admin settings for my version of Base
class QuestionAdmin(admin.ModelAdmin):
...
list_display = [
"question_text",
"created_at",
``` ...
No idea what that means, sorry
I can't do
@admin.register(Base)
class BaseAdmin(admin.ModelAdmin):
...
or any variation of this
what do you mean by "can't"? Is your keyboard broken? ๐
Python throws an error ๐
why not post the error message, and maybe I can figure out what's wrong
django.core.exceptions.ImproperlyConfigured: The model TimestampedModel is abstract, so it cannot be registered with admin.
class TimestampedModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
ah, I don't use abstract models, so I don't know ๐
looks like adding the field to the admins for the child classes will work though.
Yea but then I have to add it to everyone
codegen probably is the fastest way to do this though without patching Django itself
well you can always make a base admin class that adds that to the list_display, and then all the other admin classes inherit from it
will try this out. New to Django so not sure of how all of this works
it's pretty complicated ๐
I've slogged through worse lmao