问题
This is a random model i created to show what im looking for. In this model the store email field is a foriegn key taken from another model which is already populated. I want the stored emails to iterate each time i create an object instead of giving me an option to filter and select.
The exported csv should be like this,
pay email
10000 xyz@gmail.com
20000 zyx@gmail.com
and so on
Here's the code
class Sample(models.Model):
pay = models.CharField(max_length=50, blank=False, null=False)
store_email = models.ForeignKey(DotsStudent, default=1,
on_delete=models.SET_DEFAULT)
class SampleResource(resources.ModelResource):
store_email = Field(column_name='store_email', attribute='store_email',
widget=ForeignKeyWidget(DotsStudent, 'email'))
# store_email = attribute, DotStudent = Model from which the key is inherited from and its attribute name
class Meta:
model = Sample
class SampleAdmin(ImportExportModelAdmin):
resource_class = SampleResource
来源:https://stackoverflow.com/questions/62270240/django-import-export-iterate-foreign-key-on-object-creation