diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 1d083cd..586d80c 100644
a
|
b
|
class RelatedField(object):
|
132 | 132 | v, field = getattr(v, v._meta.pk.name), v._meta.pk |
133 | 133 | except AttributeError: |
134 | 134 | pass |
135 | | if field: |
136 | | if lookup_type in ('range', 'in'): |
137 | | v = [v] |
138 | | v = field.get_db_prep_lookup(lookup_type, v) |
139 | | if isinstance(v, list): |
140 | | v = v[0] |
| 135 | if not field: |
| 136 | field = self.rel.get_related_field() |
| 137 | if lookup_type in ('range', 'in'): |
| 138 | v = [v] |
| 139 | v = field.get_db_prep_lookup(lookup_type, v) |
| 140 | if isinstance(v, list): |
| 141 | v = v[0] |
141 | 142 | return v |
142 | 143 | |
143 | 144 | if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'): |
… |
… |
class ManyToManyField(RelatedField, Field):
|
955 | 956 | # A ManyToManyField is not represented by a single column, |
956 | 957 | # so return None. |
957 | 958 | return None |
958 | | |
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index ec0545c..0379aed 100644
a
|
b
|
class Constraint(object):
|
278 | 278 | raise EmptyShortCircuit |
279 | 279 | |
280 | 280 | return (self.alias, self.col, db_type), params |
281 | | |
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 992bb90..3982518 100644
a
|
b
|
import tempfile
|
13 | 13 | from django.db import models |
14 | 14 | from django.core.files.storage import FileSystemStorage |
15 | 15 | |
| 16 | from fields import UUIDField |
| 17 | |
16 | 18 | # Python 2.3 doesn't have sorted() |
17 | 19 | try: |
18 | 20 | sorted |
… |
… |
class ExplicitPK(models.Model):
|
189 | 191 | def __unicode__(self): |
190 | 192 | return self.key |
191 | 193 | |
| 194 | class Bar(models.Model): |
| 195 | uuid = UUIDField(primary_key=True, db_index=True, auto=True) |
| 196 | |
| 197 | |
| 198 | class Foo(models.Model): |
| 199 | book = models.ForeignKey(Book) |
| 200 | bar = models.ForeignKey(Bar) |
| 201 | |
| 202 | class Meta: |
| 203 | unique_together = (('book', 'bar'),) |
| 204 | |
192 | 205 | __test__ = {'API_TESTS': """ |
193 | 206 | >>> from django import forms |
194 | 207 | >>> from django.forms.models import ModelForm, model_to_dict |
… |
… |
ValidationError: [u'Select a valid choice. z is not one of the available choices
|
1472 | 1485 | <tr><th><label for="id_description">Description:</label></th><td><input type="text" name="description" id="id_description" /></td></tr> |
1473 | 1486 | <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr> |
1474 | 1487 | |
| 1488 | >>> class FooForm(forms.ModelForm): |
| 1489 | ... class Meta: |
| 1490 | ... model = Foo |
| 1491 | |
| 1492 | >>> new_bar = Bar.objects.create() |
| 1493 | >>> data = { |
| 1494 | ... 'bar': str(new_bar.uuid), |
| 1495 | ... 'book': str(Book.objects.all()[0].id) |
| 1496 | ... } |
| 1497 | >>> f = FooForm(data) |
| 1498 | >>> new_foo = f.save() |
| 1499 | >>> new_foo.bar == new_bar |
| 1500 | True |
| 1501 | |
1475 | 1502 | # Clean up |
1476 | 1503 | >>> import shutil |
1477 | 1504 | >>> shutil.rmtree(temp_storage_dir) |