greeneggman
greeneggman

Reputation: 13

How to rename default django model field after creation in admin panel

I am making a simple application in Django, where I want my admins to be able to go into the admin panel and create a Level object

class Level(models.Model):
        content = models.CharField(max_length = 200)

^^ This is my simple layout for the model, only admins can create this.

However, when my admins create the Level object, it shows up like this:

How it shows up in admin panel

I don't want this, and I want that to be replaced with the string content, which is a field in my Level model

So instead of looking like above, I want it to just contain the context.

How can I do this?

Upvotes: 0

Views: 223

Answers (2)

AshSmith88
AshSmith88

Reputation: 181

You just need to change the string to be the content:

class Level(models.Model):
        content = models.CharField(max_length = 200)

    def __str__(self):
        return f"{self.content}"

Upvotes: 1

Hemal Patel
Hemal Patel

Reputation: 933

class Level(models.Model):
      content = models.CharField(max_length = 200)

      def __str__(self):
          return self.content 

Upvotes: 0

Related Questions