我刚刚安装了this django-csvimport package。现在我想覆盖管理区域窗体中的默认值。我找到了定义模型并包含当前默认文本的code here:
class CSVImport(models.Model):
""" Logging model for importing files """
model_choice = []
model_name = models.CharField(max_length=255, blank=False,
default='csvimport.Item',
help_text='Please specify the app_label.model_name',
choices=get_models())
field_list = models.TextField(blank=True,
help_text='''Enter list of fields in order only if
you dont have a header row with matching field names, eg.
"column1=shared_code,column2=org(Organisation|name)"''')
upload_file = models.FileField(upload_to='csv', storage=fs)
file_name = models.CharField(max_length=255, blank=True)
encoding = models.CharField(max_length=32, blank=True)
upload_method = models.CharField(blank=False, max_length=50,
default='manual', choices=CHOICES)
error_log = models.TextField(help_text='Each line is an import error')
import_date = models.DateField(auto_now=True)
import_user = models.CharField(max_length=255, default='anonymous',
help_text='User id as text', blank=True)
def error_log_html(self):
return re.sub('\n', '<br/>', self.error_log)
error_log_html.allow_tags = True
def __unicode__(self):
return self.upload_file.name
例如,我想用其他东西覆盖model_name
字段默认值csvimport.Item
。我有点不知所措如何覆盖这个,因为我没有csvimport的应用程序文件夹,因为它是第三部分的安装。这将是我第一次覆盖第三方安装的应用程序模型。在
现在我进一步研究了一下,不确定是否应该覆盖这个模型,或者更好地覆盖admin.py
文件的ModelAdmin
类?在
谢谢!在
我看到了整个代码,
django-csvimport
包没有提供重写代码中任何内容的功能,因此在不将应用程序复制到项目的情况下不可能重写。下面是另一个应用程序django-oauth-toolkit
的示例,它使用用户设置参数来提供修改功能。在现在的解决方案是只复制应用程序,然后修改应用程序以供自己使用。在
相关问题 更多 >
编程相关推荐