我不知道为什么但是django-admin,raw_id_fields正在向我返回一个相关的字段错误。我将解释我所做的事情以及我尝试过的不同方法。
对于这个特殊情况,我有5种不同的模型:
我在所有模型中使用原始ID都没有问题,但在# Models.py
class System(models.Model):
system_name = models.CharField(max_length=20, null=False, verbose_name='System')
version = models.CharField(max_length=20, blank=True, verbose_name='Version')
class Meta:
unique_together = (('system_name', 'version'),)
class Extract(models.Model):
extract_name = models.CharField(max_length=20, null=False, verbose_name='Extract Name')
system = models.ForeignKey(System, related_name='extracts', on_delete=models.CASCADE, verbose_name='System')
def __str__(self):
return 'Mapping of {} into {}'.format(self.mapping_system, self.destination_system)
class Meta:
unique_together = (('extract_name', 'system'),)
class Mapping(models.Model):
destination_system = models.ForeignKey(System, on_delete=models.CASCADE, related_name='mappings',
verbose_name='Destination System')
mapping_system = models.ForeignKey(System, on_delete=models.CASCADE, related_name='maps_into',
verbose_name='Input System')
mapping_description = models.TextField(blank=True, null=True)
class Meta:
unique_together = (('mapping', 'destination_extract', 'mapping_concept'),)
class MappingTargetTableConceptSources(models.Model):
mapping_target_table_concept = models.ForeignKey(MappingTargetTableConcept, on_delete=models.CASCADE,
related_name='is_used', verbose_name='Mapping Concept')
destination = models.ForeignKey(Extract, on_delete=models.CASCADE, verbose_name='Source Table')
class Meta:
unique_together = (('mapping_target_table_concept', 'source', ),)
模型中使用管理搜索引擎时返回臭名昭着的icontains错误。
admin.py
在# admin.py
class MappingTargetTableConceptManager(admin.ModelAdmin):
raw_id_fields = ('destination_extract',)
admin.site.register(MappingTargetTableConcept, MappingTargetTableConceptManager)
中,我只想调用MappingTargetTableConcept的目标提取中的原始id
Extract.objects.filter(extract_name__icontains='Contract')
管理员显示用于搜索的放大镜,弹出窗口显示,但是当在弹出窗口中查找我想要的提取物(或其他任何内容)时,它会带来。在控制台中,这可以使用{{1}}
我尝试将raw_id替换为`raw_id_fields =(' destination_extract__extract_name',)..没有成功
答案 0 :(得分:0)
我能够解决它..问题(或者至少修复它的方式是提取的相关modeladmin中的搜索字段)
我有:
class ExtractManager2(admin.ModelAdmin):
search_fields = ('system', 'extract_name', 'tech_name', 'description', )
当我将其更改为:
class ExtractManager2(admin.ModelAdmin):
search_fields = ('extract_name',)
有效..