Django进出口名称'name'未定义

时间:2019-01-24 07:36:30

标签: python django excel import

您好,我需要在django管理员中导入excel文件,我找到了此视频,并应用了步骤,但是我有行号:1 - name 'name' is not defined error该如何解决?

models.py

from django.db import models


class Ekle(models.Model):
    name = models.CharField(max_length = 50, blank = False)
    lastname = models.CharField(max_length = 50)
    price = models.CharField(max_length = 50)

    def __str__(self):
        return name

admin.py

from django.contrib import admin
from .models import *
from import_export.admin import ImportExportModelAdmin


@admin.register(Ekle)
class ViewAdmin(ImportExportModelAdmin):
    pass

1 个答案:

答案 0 :(得分:0)

您需要同时使用self:

def __str__(self):
    return "%s" % self.name