def update_achievements(self, request, queryset):
for sender in queryset:
sender.update_achievements()
def update_achievements(self):
self.achievements.clear()
if self.countries().count() > 2:
achievement, created = Achievement.objects.get_or_create(name='3 Countries')
self.achievements.add(achievement)
if self.countries().count() > 4:
achievement, created = Achievement.objects.get_or_create(name='5 Countries')
self.achievements.add(achievement)
if self.countries().count() > 9:
achievement, created = Achievement.objects.get_or_create(name='10 Countries')
self.achievements.add(achievement)
if self.countries().count() > 49:
achievement, created = Achievement.objects.get_or_create(name='50 Countries')
self.achievements.add(achievement)
if self.cities().count() > 2:
achievement, created = Achievement.objects.get_or_create(name='3 Cities')
self.achievements.add(achievement)
if self.cities().count() > 4:
achievement, created = Achievement.objects.get_or_create(name='5 Cities')
self.achievements.add(achievement)
if self.cities().count() > 9:
achievement, created = Achievement.objects.get_or_create(name='10 Cities')
self.achievements.add(achievement)
if self.cities().count() > 49:
achievement, created = Achievement.objects.get_or_create(name='50 Cities')
self.achievements.add(achievement)
if self.languages().count() > 2:
achievement, created = Achievement.objects.get_or_create(name='3 Languages')
self.achievements.add(achievement)
if self.languages().count() > 4:
achievement, created = Achievement.objects.get_or_create(name='5 Languages')
self.achievements.add(achievement)
if self.languages().count() > 9:
achievement, created = Achievement.objects.get_or_create(name='10 Languages')
self.achievements.add(achievement)
if self.languages().count() > 49:
achievement, created = Achievement.objects.get_or_create(name='50 Languages')
self.achievements.add(achievement)
if len(set([ newspaper.city.continent for newspaper in self.newspapers() ])) > 1:
achievement, created = Achievement.objects.get_or_create(name='2 Continents')
self.achievements.add(achievement)
if len(set([ newspaper.city.continent for newspaper in self.newspapers() ])) > 2:
achievement, created = Achievement.objects.get_or_create(name='3 Continents')
self.achievements.add(achievement)
if len(set([ newspaper.city.continent for newspaper in self.newspapers() ])) > 3:
achievement, created = Achievement.objects.get_or_create(name='4 Continents')
self.achievements.add(achievement)
if len(set([ newspaper.city.continent for newspaper in self.newspapers() ])) > 4:
achievement, created = Achievement.objects.get_or_create(name='5 Continents')
self.achievements.add(achievement)
if len(set([ newspaper.city.continent for newspaper in self.newspapers() ])) > 5:
achievement, created = Achievement.objects.get_or_create(name='6 Continents')
self.achievements.add(achievement)
if len(set([ newspaper.city.hemisphere() for newspaper in self.newspapers() ])) == 2:
achievement, created = Achievement.objects.get_or_create(name='Both Hemisphere')
self.achievements.add(achievement)
years = len(set([ newspaper.date.year for newspaper in self.newspapers() ]))
if years > 3:
achievement, created = Achievement.objects.get_or_create(name='3 Years')
self.achievements.add(achievement)
if years > 4:
achievement, created = Achievement.objects.get_or_create(name='5 Years')
self.achievements.add(achievement)
if years > 9:
achievement, created = Achievement.objects.get_or_create(name='10 Years')
self.achievements.add(achievement)
self.save()