这是我的model.py.我已经在管理面板上注册了这个模型。我想用数据填充我的模型。该数据将来自另一个模型,我将对其进行一些计算并将该数据放入该模型中。任何帮助家伙。如何使用admin django中的数据填充我的模型?
class Sectorcapitalratios(models.Model):
sectorserialnum = models.IntegerField(db_column='SectorSerialNum', primary_key=True) # Field name made lowercase.
sectorname = models.CharField(db_column='SectorName', max_length=50, blank=True, null=True) # Field name made lowercase.
years = models.CharField(db_column='Years', max_length=15) # Field name made lowercase.
debttoequityratio = models.FloatField(db_column='DebtToEquityRatio', blank=True, null=True) # Field name made lowercase.
debttocapital = models.FloatField(db_column='DebtToCapital', blank=True, null=True) # Field name made lowercase.
debttototalassets = models.FloatField(db_column='DebtToTotalAssets', blank=True, null=True) # Field name made lowercase.
timestamp =models.DateTimeField(auto_now_add = True) #This will create the time
class Meta:
db_table = 'sectorcapitalratios'
unique_together = (('sectorserialnum', 'years'),)
#def __str__(self):
# return self.sectorserialnum
Admin.py
class CapitalratiosResource(resources.ModelResource):
class Meta:
model = Capitalratios
skip_unchanged = True
report_skipped = False
import_id_fields = ('ticker','years')
class CapitalratiosAdmin(ImportExportModelAdmin,admin.ModelAdmin):
resource_class = CapitalratiosResource
list_display = ('ticker','years','debttoequityratio','debttocapital','debttototalassets')
#Register the Capital Ratios model and admin with the admin
admin.site.register(Capitalratios, CapitalratiosAdmin)