admin.site.register(RegistrationOTP)
class RegistrationOTPResource(resources.ModelResource):
class Meta:
model = RegistrationOTP
export_order = ('country','phone_number','otp','created_date','is_verified')
class RegistrationOTPAdmin(ImportExportModelAdmin):
resource_class = RegistrationOTPResource
这是models.py
class RegistrationOTP(models.Model):
country = models.ForeignKey(Country,on_delete=models.CASCADE, related_name='otp_country', default=1)
phone_number = models.CharField(max_length=13)#, unique=True, validators=[phone_regex],
otp = models.PositiveIntegerField()
created_date = models.DateTimeField(auto_now=True)
is_verified = models.CharField(choices=YES_OR_NO, default='no', max_length=10)
def __unicode__(self):
return '%s : %s'% (self.phone_number, self.otp)
我在这里按照文档进行操作,但未在管理员中显示export csv选项
答案 0 :(得分:1)
class RegistrationOTPResource(resources.ModelResource):
class Meta:
model = RegistrationOTP
fields = '__all__'
export_order = ('id','country','phone_number','otp','created_date','is_verified')
尝试一下,我猜由于缺少字段部分,它不起作用