简体   繁体   中英

Application profile not returning proper name in Django app

Recently started learning django and as an initial step, i created an application called profiles within my django app. Now from the admin page i opened that app and added a profile with a name and description however when i save it, it doesnt return the proper name, it just returns "profile name(1)" where as i have specifically asked it to return name. here is the models.py code

from __future__ import unicode_literals
from django.db import models


#Create your models here.
class profile(models.Model):
    name = models.CharField(max_length=120)
    description = models.TextField(default='description default text')

    def __unicode__(self):
        return self.name

added the app in settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'profiles',
]

here is the admin.py file

from django.contrib import admin

# Register your models here.
from .models import profile

class profileAdmin(admin.ModelAdmin):
    class Meta:
        model=profile

admin.site.register(profile,profileAdmin)

its probably something very silly which I am not able to point out but I checked and recheckeed if I am using the right 'profiles' and 'profile' everywhere. Also asking so that i can get a better understanding of what this actually is.

I am also addind a pic from my sublime editor the circled part shows in a different color in the tutorial I am learning this from, maybe becuase its an older version of editor from 3 yeras ago but i wnated to confirm if its taking profile as a class name and not something else. 在此处输入图像描述

It seems like you are using python3+ so use the __str__ method instead of unicode

def __str__(self):
     return self.name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM