Repository: encode/django-rest-framework

Issue:
Bug : JSON integer won't match integer in a ChoiceField
I have a Model with : 

```
PENDING = 1
COMPLETE = 2
CANCELLED = 3
STATUS = (
    (PENDING, 'Pending'),
    (COMPLETE, 'Complete'),
    (CANCELLED, 'Cancelled'),
)
(...)
status = models.PositiveIntegerField(default=COMPLETE, choices=STATUS)
```

And when I perform a PUT  (update) on that model (using the default ModelSerializer) with the following JSON : 

```
{"id":8,"status":3,"t_type":1,"description":"Transaction example"}
```

I get the following error message : 

```
"status" : "Select a valid choice. 3 is not one of the available choices."
```

Which it clearly is. 

Bug : JSON integer won't match integer in a ChoiceField
I have a Model with : 

```
PENDING = 1
COMPLETE = 2
CANCELLED = 3
STATUS = (
    (PENDING, 'Pending'),
    (COMPLETE, 'Complete'),
    (CANCELLED, 'Cancelled'),
)
(...)
status = models.PositiveIntegerField(default=COMPLETE, choices=STATUS)
```

And when I perform a PUT  (update) on that model (using the default ModelSerializer) with the following JSON : 

```
{"id":8,"status":3,"t_type":1,"description":"Transaction example"}
```

I get the following error message : 

```
"status" : "Select a valid choice. 3 is not one of the available choices."
```

Which it clearly is. 



Discussion:

Resolving patch:
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -794,7 +794,7 @@ def valid_value(self, value):
                     if value == smart_unicode(k2):
                         return True
             else:
-                if value == smart_unicode(k):
+                if value == smart_unicode(k) or value == k:
                     return True
         return False
 


Test patch:
diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py
--- a/rest_framework/tests/models.py
+++ b/rest_framework/tests/models.py
@@ -51,6 +51,10 @@ class Meta:
         abstract = True
 
 
+class HasPositiveIntegerAsChoice(RESTFrameworkModel):
+    some_choices = ((1,'A'),(2,'B'),(3,'C'))
+    some_integer = models.PositiveIntegerField(choices=some_choices)
+
 class Anchor(RESTFrameworkModel):
     text = models.CharField(max_length=100, default='anchor')
 
diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py
--- a/rest_framework/tests/serializer.py
+++ b/rest_framework/tests/serializer.py
@@ -2,7 +2,7 @@
 import pickle
 from django.test import TestCase
 from rest_framework import serializers
-from rest_framework.tests.models import (Album, ActionItem, Anchor, BasicModel,
+from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
     BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
     ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
 
@@ -69,6 +69,11 @@ class Meta:
         model = Album
         fields = ['title']  # lists are also valid options
 
+class PositiveIntegerAsChoiceSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = HasPositiveIntegerAsChoice
+        fields = ['some_integer']
+
 
 class BasicTests(TestCase):
     def setUp(self):
@@ -285,6 +290,12 @@ def test_default_modelfield_max_length_exceeded(self):
         self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']})
 
 
+class PositiveIntegerAsChoiceTests(TestCase):
+    def test_positive_integer_in_json_is_correctly_parsed(self):
+        data = {'some_integer':1}
+        serializer = PositiveIntegerAsChoiceSerializer(data=data)
+        self.assertEquals(serializer.is_valid(), True)
+
 class ModelValidationTests(TestCase):
     def test_validate_unique(self):
         """