Now I have this code:
class Mymodel(models.Model):
xxxx_count = ForeignCountField(filter={'foreign_table__xxxx': True})
yyyy_count = ForeignCountField(filter={'foreign_table__yyyy': True})
zzzz_count = ForeignCountField(filter={'foreign_table__zzzz': True})
qqqq_count = ForeignCountField(filter={'foreign_table__qqqq': True})
ssss_count = ForeignCountField(filter={'foreign_table__ssss': True})
rrrr_count = ForeignCountField(filter={'foreign_table__rrrr': True})
I want something like this:
class Mymodel(models.Model):
for code in ['xxxx','yyyy','zzzz','qqqq','ssss','rrrr']:
setattr(self, '%s_count' % code, ForeignCountField(filter={'foreign_table__%s' % code: True}))
But when I try to do this, error raised: "self doesn't defined". Do I need to put this code into some other place?