def add(self, score, user, ip_address, cookies={}, commit=True):
try:<EOL><INDENT>score = int(score)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>raise InvalidRating("<STR_LIT>" % (score, self.field.name))<EOL><DEDENT>delete = (score == <NUM_LIT:0>)<EOL>if delete and not self.field.allow_delete:<EOL><INDENT>raise CannotDeleteVote("<STR_LIT>" % (self.field.name,))<EOL><DEDENT>if score < <NUM_LIT:0> or score > self.field.range:<EOL><INDENT>raise InvalidRating("<STR_LIT>" % (score, self.field.name))<EOL><DEDENT>is_anonymous = (user is None or not user.is_authenticated())<EOL>if is_anonymous and not self.field.allow_anonymous:<EOL><INDENT>raise AuthRequired("<STR_LIT>" % (user,))<EOL><DEDENT>if is_anonymous:<EOL><INDENT>user = None<EOL><DEDENT>defaults = dict(<EOL>score = score,<EOL>ip_address = ip_address,<EOL>)<EOL>kwargs = dict(<EOL>content_type    = self.get_content_type(),<EOL>object_id       = self.instance.pk,<EOL>key             = self.field.key,<EOL>user            = user,<EOL>)<EOL>if not user:<EOL><INDENT>kwargs['<STR_LIT>'] = ip_address<EOL><DEDENT>use_cookies = (self.field.allow_anonymous and self.field.use_cookies)<EOL>if use_cookies:<EOL><INDENT>defaults['<STR_LIT>'] = now().strftime('<STR_LIT>') <EOL>cookie_name = '<STR_LIT>' % (kwargs['<STR_LIT>'].pk, kwargs['<STR_LIT>'], kwargs['<STR_LIT:key>'][:<NUM_LIT:6>],) <EOL>cookie = cookies.get(cookie_name) <EOL>if not cookie:<EOL><INDENT>kwargs['<STR_LIT>'] = True<EOL><DEDENT>kwargs['<STR_LIT>'] = cookie<EOL><DEDENT>try:<EOL><INDENT>rating, created = Vote.objects.get(**kwargs), False<EOL><DEDENT>except Vote.DoesNotExist:<EOL><INDENT>if delete:<EOL><INDENT>raise CannotDeleteVote("<STR_LIT>" % (self.field.name,))<EOL><DEDENT>if getattr(settings, '<STR_LIT>', RATINGS_VOTES_PER_IP):<EOL><INDENT>num_votes = Vote.objects.filter(<EOL>content_type=kwargs['<STR_LIT>'],<EOL>object_id=kwargs['<STR_LIT>'],<EOL>key=kwargs['<STR_LIT:key>'],<EOL>ip_address=ip_address,<EOL>).count()<EOL>if num_votes >= getattr(settings, '<STR_LIT>', RATINGS_VOTES_PER_IP):<EOL><INDENT>raise IPLimitReached()<EOL><DEDENT><DEDENT>kwargs.update(defaults)<EOL>if use_cookies:<EOL><INDENT>cookie = defaults['<STR_LIT>'] <EOL>kwargs.pop('<STR_LIT>', '<STR_LIT>') <EOL><DEDENT>rating, created = Vote.objects.create(**kwargs), True<EOL><DEDENT>has_changed = False<EOL>if not created:<EOL><INDENT>if self.field.can_change_vote:<EOL><INDENT>has_changed = True<EOL>self.score -= rating.score<EOL>if not delete:<EOL><INDENT>rating.score = score<EOL>rating.save()<EOL><DEDENT>else:<EOL><INDENT>self.votes -= <NUM_LIT:1><EOL>rating.delete()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CannotChangeVote()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>has_changed = True<EOL>self.votes += <NUM_LIT:1><EOL><DEDENT>if has_changed:<EOL><INDENT>if not delete:<EOL><INDENT>self.score += rating.score<EOL><DEDENT>if commit:<EOL><INDENT>self.instance.save()<EOL><DEDENT>defaults = dict(<EOL>score   = self.score,<EOL>votes   = self.votes,<EOL>)<EOL>kwargs = dict(<EOL>content_type    = self.get_content_type(),<EOL>object_id       = self.instance.pk,<EOL>key             = self.field.key,<EOL>)<EOL>try:<EOL><INDENT>score, created = Score.objects.get(**kwargs), False<EOL><DEDENT>except Score.DoesNotExist:<EOL><INDENT>kwargs.update(defaults)<EOL>score, created = Score.objects.create(**kwargs), True<EOL><DEDENT>if not created:<EOL><INDENT>score.__dict__.update(defaults)<EOL>score.save()<EOL><DEDENT><DEDENT>adds = {}<EOL>if use_cookies:<EOL><INDENT>adds['<STR_LIT>'] = cookie_name<EOL>adds['<STR_LIT>'] = cookie<EOL><DEDENT>if delete:<EOL><INDENT>adds['<STR_LIT>'] = True<EOL><DEDENT>return adds<EOL>
add(score, user, ip_address)

        Used to add a rating to an object.