Reputation: 33
Fields Don't show in django admin While trying to add role through django admin it doesn't show the field
class Role(Core):
role = models.CharField(max_length=25, unique=True, editable=False)
def save(self, *args, **kwargs):
self.role = self.role.lower()
super(Role, self).save(*args, **kwargs)
def __str__(self):
return self.role.capitalize()
admin.site.register(Role)
class Core(models.Model):
id = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
Upvotes: 3
Views: 1427
Reputation: 476624
The id
is given by the database (it is the primary key) and the created_at
and updated_at
are items that are non-editable, so these will not show in the form either.
This thus means that role
would be the only field that can be used, but you specified this as editable=False
[Django-doc], hence it will not show up to create/edit a Role
object.
You should remove the editable=False
part:
class Role(Core):
# no editable = False ↓
role = models.CharField(max_length=25, unique=True)
def save(self, *args, **kwargs):
self.role = self.role.lower()
super(Role, self).save(*args, **kwargs)
def __str__(self):
return self.role.capitalize()
Upvotes: 4