KaoriYui
KaoriYui

Reputation: 922

Putting a search bar on admin model Python/Django

I am new with python and django, i want to know how can i implement the admin search bar on my project model? i notice that the user model has it by default.

enter image description here

My code is below, after the makemigration command still no search bar i think i am missing something. sorry for the noob question.

class Todo(models.Model):
    search_fields = ('title', 'text', 'created_at',)
    title = models.CharField(max_length=200)
    text = models.TextField()
    created_at = models.DateTimeField(default=datetime.now)
    def __str__(self):
        return self.title

Upvotes: 0

Views: 378

Answers (2)

Exprator
Exprator

Reputation: 27513

in the apps admin.py

inside the class for which you are registering the model

add

search_fields = ['column_name']

Upvotes: 2

Manpreet Ahluwalia
Manpreet Ahluwalia

Reputation: 331

add search fields in admin file instead of models file

Upvotes: 1

Related Questions