0

I am trying to implemet django-updown https://github.com/weluse/django-updown. When I try to add vote trough the admin panel it says Value 1 not a valid choice.

This is the models.py from the application:

_SCORE_TYPE_CHOICES = (
('-1', 'DISLIKE'),
('1', 'LIKE'),
)

SCORE_TYPES = dict((value, key) for key, value in _SCORE_TYPE_CHOICES)

class Vote(models.Model):
    content_type = models.ForeignKey(ContentType, related_name="updown_votes")
    object_id = models.PositiveIntegerField()
    key = models.CharField(max_length=32)
    score = models.SmallIntegerField(choices=_SCORE_TYPE_CHOICES)
    user = models.ForeignKey(User, blank=True, null=True, related_name="updown_votes")
    ip_address = models.IPAddressField()
    date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
    date_changed = models.DateTimeField(default=datetime.datetime.now, editable=False)

Do you have an idea what could be wrong?

Charles
  • 50,943
  • 13
  • 104
  • 142
tamara
  • 120
  • 1
  • 12

2 Answers2

3

Your score field is a SmallIntegerField so try using integers instead of strings in your choices tuples and it should work:

_SCORE_TYPE_CHOICES = (
    (-1, 'DISLIKE'),
    (1, 'LIKE'),
)
arie
  • 18,737
  • 5
  • 70
  • 76
  • It actually was like that in the beginning, but I tried with strings as a suggestion I found somewhere on the internet. – tamara Jun 15 '12 at 12:35
  • 1
    Hm ... integers should be fine. You could even improve your approach using constants: http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/ Did you eventually change the field type of your choices field? What happens if you try to set a score via shell? What does the error message exactly look like? – arie Jun 15 '12 at 12:42
  • I actually don't know how to do that. It says to vote do "submit a vote just go to //rate/(1|-1). " but when I go to that url nothing happens. – tamara Jun 15 '12 at 12:53
  • Sorry, i haven't used that app, so this is a bit out of scope for me. But the github page mentions a RatingField which i can't spot on your model. So make sure that you really follow the instructions. – arie Jun 15 '12 at 13:04
  • The RatingField is in the model that uses this code, this is the model from the application, I posted it because I thought there is a problem there. – tamara Jun 15 '12 at 13:10
0

At the end, there was no solution for this, so I installed django-ratings https://github.com/dcramer/django-ratings and it works fine. So if you have this kind of issue, I recommend this application.

tamara
  • 120
  • 1
  • 12