首页 > 解决方案 > Django 管理站点添加“城市对象”而不是“城市”

问题描述

我正在尝试在 Django 上创建一个基本的天气预报网站,但出现了这个错误。我成功创建了“城市”部分,但是在添加任何城市名称时,会添加“城市对象 1”。这会在从 API 密钥读取 JSON 时产生错误。

from django.db import models

class City(models.Model):
    name = models.CharField(max_length=25)

    def _str_(self): #show the actual city name on the dashboard
        return self.name

    class Meta: #show the plural of city as cities instead of citys
        verbose_name_plural = 'cities'

管理员.py

from django.contrib import admin
from .models import City

admin.site.register(City)

标签: pythondjango

解决方案



推荐阅读