我遇到这种情况:
class Item (models.Model):
name = models.Charfield(MaxLenght=15)
class ItemIsHired(models.Model):
item = models.ForeignKey(Item)
isHiredNow = models.BooleanField(null=False)
问题是我想要检索现在雇用的所有项目,但是如果我使用ItemIsHired.objects.filter(isHiredNow=True)
进行查询,当我需要来自ItemIsHired
类时,我会从def valueChartPatterns(dict,path):
seen_values = Counter()
for data in dict.itervalues():
seen_values += Counter(data.values())
seen_values = seen_values.most_common()
seen_values_pct = map(itemgetter(1), tupleCounts2Percents(seen_values))
seen_values_pct = ['{:.2%}'.format(item)for item in seen_values_pct]
plt.figure()
numberchart = plt.bar(range(len(seen_values)), map(itemgetter(1), seen_values), width=0.9,align='center')
plt.xticks(range(len(seen_values)), map(itemgetter(0), seen_values))
plt.title('Values in Pattern Dataset')
plt.xlabel('Values in Data')
plt.ylabel('Occurrences')
plt.tick_params(axis='both', which='major', labelsize=6)
plt.tick_params(axis='both', which='minor', labelsize=6)
plt.tight_layout()
plt.savefig(path)
plt.clf()
def countryChartPatterns(dict,path):
seen_countries = Counter()
for data in dict.itervalues():
seen_countries += Counter(data.keys())
seen_countries = seen_countries.most_common()
seen_countries_percentage = map(itemgetter(1), tupleCounts2Percents(seen_countries))
seen_countries_percentage = ['{:.2%}'.format(item)for item in seen_countries_percentage]
yvals = map(itemgetter(1), seen_countries)
xvals = map(itemgetter(0), seen_countries)
plt.figure()
countrychart = plt.bar(range(len(seen_countries)), yvals, width=0.9,align='center')
plt.xticks(range(len(seen_countries)), xvals)
plt.title('Countries in Pattern Dataset')
plt.xlabel('Countries in Data')
plt.ylabel('Occurrences')
plt.tick_params(axis='both', which='major', labelsize=6)
plt.tick_params(axis='both', which='minor', labelsize=6)
plt.tight_layout()
plt.savefig(path)
plt.clf()
类获取对象与他们相关的Item类。