Skip to content

Commit d86d77c

Browse files
committed
Update GenericForeignKey object_id to CharField/TextField
MongoDB uses ObjectId rather than integer
1 parent a6c3b9a commit d86d77c

File tree

15 files changed

+55
-54
lines changed

15 files changed

+55
-54
lines changed

tests/admin_filters/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TaggedItem(models.Model):
7777
content_type = models.ForeignKey(
7878
ContentType, models.CASCADE, related_name="tagged_items"
7979
)
80-
object_id = models.PositiveIntegerField()
80+
object_id = models.TextField()
8181
content_object = GenericForeignKey("content_type", "object_id")
8282

8383
def __str__(self):

tests/admin_inlines/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Child(models.Model):
2929
teacher = models.ForeignKey(Teacher, models.CASCADE)
3030

3131
content_type = models.ForeignKey(ContentType, models.CASCADE)
32-
object_id = models.PositiveIntegerField()
32+
object_id = models.TextField()
3333
parent = GenericForeignKey()
3434

3535
def __str__(self):

tests/admin_views/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class FunkyTag(models.Model):
545545
"Because we all know there's only one real use case for GFKs."
546546
name = models.CharField(max_length=25)
547547
content_type = models.ForeignKey(ContentType, models.CASCADE)
548-
object_id = models.PositiveIntegerField()
548+
object_id = models.TextField()
549549
content_object = GenericForeignKey("content_type", "object_id")
550550

551551
def __str__(self):
@@ -1048,7 +1048,7 @@ class ImplicitlyGeneratedPK(models.Model):
10481048
# Models for #25622
10491049
class ReferencedByGenRel(models.Model):
10501050
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
1051-
object_id = models.PositiveIntegerField()
1051+
object_id = models.TextField()
10521052
content_object = GenericForeignKey("content_type", "object_id")
10531053

10541054

tests/contenttypes_tests/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Question(models.Model):
7777
class Answer(models.Model):
7878
text = models.CharField(max_length=200)
7979
content_type = models.ForeignKey(ContentType, models.CASCADE)
80-
object_id = models.PositiveIntegerField()
80+
object_id = models.CharField(max_length=24)
8181
question = GenericForeignKey()
8282

8383
class Meta:
@@ -89,7 +89,7 @@ class Post(models.Model):
8989

9090
title = models.CharField(max_length=200)
9191
content_type = models.ForeignKey(ContentType, models.CASCADE, null=True)
92-
object_id = models.PositiveIntegerField(null=True)
92+
object_id = models.TextField(null=True)
9393
parent = GenericForeignKey()
9494
children = GenericRelation("Post")
9595

tests/custom_managers/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Person(models.Model):
106106
favorite_thing_type = models.ForeignKey(
107107
"contenttypes.ContentType", models.SET_NULL, null=True
108108
)
109-
favorite_thing_id = models.IntegerField(null=True)
109+
favorite_thing_id = models.TextField()
110110
favorite_thing = GenericForeignKey("favorite_thing_type", "favorite_thing_id")
111111

112112
objects = PersonManager()
@@ -134,7 +134,7 @@ class FunPerson(models.Model):
134134
favorite_thing_type = models.ForeignKey(
135135
"contenttypes.ContentType", models.SET_NULL, null=True
136136
)
137-
favorite_thing_id = models.IntegerField(null=True)
137+
favorite_thing_id = models.TextField()
138138
favorite_thing = GenericForeignKey("favorite_thing_type", "favorite_thing_id")
139139

140140
objects = FunPeopleManager()

tests/delete/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,21 @@ class DeleteBottom(models.Model):
219219

220220
class GenericB1(models.Model):
221221
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
222-
object_id = models.PositiveIntegerField()
222+
object_id = models.CharField(max_length=24)
223223
generic_delete_top = GenericForeignKey("content_type", "object_id")
224224

225225

226226
class GenericB2(models.Model):
227227
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
228-
object_id = models.PositiveIntegerField()
228+
object_id = models.CharField(max_length=24)
229229
generic_delete_top = GenericForeignKey("content_type", "object_id")
230230
generic_delete_bottom = GenericRelation("GenericDeleteBottom")
231231

232232

233233
class GenericDeleteBottom(models.Model):
234234
generic_b1 = models.ForeignKey(GenericB1, models.RESTRICT)
235235
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
236-
object_id = models.PositiveIntegerField()
236+
object_id = models.CharField(max_length=24)
237237
generic_b2 = GenericForeignKey()
238238

239239

tests/delete_regress/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Award(models.Model):
77
name = models.CharField(max_length=25)
8-
object_id = models.PositiveIntegerField()
8+
object_id = models.CharField(max_length=24)
99
content_type = models.ForeignKey(ContentType, models.CASCADE)
1010
content_object = GenericForeignKey()
1111

tests/filtered_relation/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Author(models.Model):
1111
related_query_name="preferred_by_authors",
1212
)
1313
content_type = models.ForeignKey(ContentType, models.CASCADE, null=True)
14-
object_id = models.PositiveIntegerField(null=True)
14+
object_id = models.TextField(null=True)
1515
content_object = GenericForeignKey()
1616

1717

tests/generic_inline_admin/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Media(models.Model):
1515
"""
1616

1717
content_type = models.ForeignKey(ContentType, models.CASCADE)
18-
object_id = models.PositiveIntegerField()
18+
object_id = models.TextField()
1919
content_object = GenericForeignKey()
2020
url = models.URLField()
2121
description = models.CharField(max_length=100, blank=True)
@@ -34,7 +34,7 @@ class Category(models.Model):
3434

3535
class PhoneNumber(models.Model):
3636
content_type = models.ForeignKey(ContentType, models.CASCADE)
37-
object_id = models.PositiveIntegerField()
37+
object_id = models.TextField()
3838
content_object = GenericForeignKey("content_type", "object_id")
3939
phone_number = models.CharField(max_length=30)
4040
category = models.ForeignKey(Category, models.SET_NULL, null=True, blank=True)

tests/generic_relations/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TaggedItem(models.Model):
1919

2020
tag = models.SlugField()
2121
content_type = models.ForeignKey(ContentType, models.CASCADE)
22-
object_id = models.PositiveIntegerField()
22+
object_id = models.TextField()
2323

2424
content_object = GenericForeignKey()
2525

@@ -40,7 +40,7 @@ class AbstractComparison(models.Model):
4040
content_type1 = models.ForeignKey(
4141
ContentType, models.CASCADE, related_name="comparative1_set"
4242
)
43-
object_id1 = models.PositiveIntegerField()
43+
object_id1 = models.TextField()
4444

4545
first_obj = GenericForeignKey(ct_field="content_type1", fk_field="object_id1")
4646

@@ -54,7 +54,7 @@ class Comparison(AbstractComparison):
5454
content_type2 = models.ForeignKey(
5555
ContentType, models.CASCADE, related_name="comparative2_set"
5656
)
57-
object_id2 = models.PositiveIntegerField()
57+
object_id2 = models.TextField()
5858

5959
other_obj = GenericForeignKey(ct_field="content_type2", fk_field="object_id2")
6060

@@ -119,20 +119,20 @@ class ValuableRock(Mineral):
119119

120120

121121
class ManualPK(models.Model):
122-
id = models.IntegerField(primary_key=True)
122+
id = models.TextField(primary_key=True)
123123
tags = GenericRelation(TaggedItem, related_query_name="manualpk")
124124

125125

126126
class ForProxyModelModel(models.Model):
127127
content_type = models.ForeignKey(ContentType, models.CASCADE)
128-
object_id = models.PositiveIntegerField()
128+
object_id = models.TextField()
129129
obj = GenericForeignKey(for_concrete_model=False)
130130
title = models.CharField(max_length=255, null=True)
131131

132132

133133
class ForConcreteModelModel(models.Model):
134134
content_type = models.ForeignKey(ContentType, models.CASCADE)
135-
object_id = models.PositiveIntegerField()
135+
object_id = models.TextField()
136136
obj = GenericForeignKey()
137137

138138

0 commit comments

Comments
 (0)