0

In django admin, I have a model in which there are several objects. Now in admin, I have the link to Mymodel. If i click that, I get a list, all of which say

Mymodel object

If I need to find a particular record from the table, then I simply have to search the whole list. How can I change the setting so that instead of MyModel object I get to see an attribute, say name of that particular object??

1

1 Answer 1

5

You should define __unicode__ method in your model class:

def __unicode__(self):
    return self.name # to display name attribute

From django docs:

The __unicode__() method is called whenever you call unicode() on an object. Django uses unicode(obj) (or the related function, str(obj)) in a number of places. Most notably, to display an object in the Django admin site and as the value inserted into a template when it displays an object. Thus, you should always return a nice, human-readable representation of the model from the __unicode__() method.

Sign up to request clarification or add additional context in comments.

2 Comments

Should I syncdb again?
@AswinMurugesh no, no changes in db

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.