Skip to content

Commit

Permalink
Using textfield instead of ObjectIdField.
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV committed Sep 23, 2024
1 parent 640aef4 commit 8bf77cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions django/contrib/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.utils.text import get_text_list
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django_mongodb.fields import ObjectIdField

ADDITION = 1
CHANGE = 2
Expand Down Expand Up @@ -64,7 +63,7 @@ class LogEntry(models.Model):
blank=True,
null=True,
)
object_id = ObjectIdField(_("object id"), blank=True, null=True)
object_id = models.TextField(_("object id"), blank=True, null=True)
# Translators: 'repr' means representation
# (https://docs.python.org/library/functions.html#repr)
object_repr = models.CharField(_("object repr"), max_length=200)
Expand Down
13 changes: 6 additions & 7 deletions tests/generic_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django_mongodb.fields import ObjectIdField


class TaggedItem(models.Model):
"""A tag on an item."""

tag = models.SlugField()
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = ObjectIdField()
object_id = models.TextField()

content_object = GenericForeignKey()

Expand All @@ -41,7 +40,7 @@ class AbstractComparison(models.Model):
content_type1 = models.ForeignKey(
ContentType, models.CASCADE, related_name="comparative1_set"
)
object_id1 = ObjectIdField()
object_id1 = models.TextField()

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

Expand All @@ -55,7 +54,7 @@ class Comparison(AbstractComparison):
content_type2 = models.ForeignKey(
ContentType, models.CASCADE, related_name="comparative2_set"
)
object_id2 = ObjectIdField()
object_id2 = models.TextField()

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

Expand Down Expand Up @@ -120,20 +119,20 @@ class ValuableRock(Mineral):


class ManualPK(models.Model):
id = ObjectIdField(primary_key=True)
id = models.TextField(primary_key=True)
tags = GenericRelation(TaggedItem, related_query_name="manualpk")


class ForProxyModelModel(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = ObjectIdField()
object_id = models.TextField()
obj = GenericForeignKey(for_concrete_model=False)
title = models.CharField(max_length=255, null=True)


class ForConcreteModelModel(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = ObjectIdField()
object_id = models.TextField()
obj = GenericForeignKey()


Expand Down
3 changes: 2 additions & 1 deletion tests/generic_relations/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from bson import ObjectId

Check failure on line 1 in tests/generic_relations/tests.py

View workflow job for this annotation

GitHub Actions / isort

Imports are incorrectly sorted and/or formatted.
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.prefetch import GenericPrefetch
from django.core.exceptions import FieldError
Expand Down Expand Up @@ -44,7 +45,7 @@ def setUpTestData(cls):

def comp_func(self, obj):
# Original list of tags:
return obj.tag, obj.content_type.model_class(), obj.object_id
return obj.tag, obj.content_type.model_class(), ObjectId(obj.object_id)

async def test_generic_async_acreate(self):
await self.bacon.tags.acreate(tag="orange")
Expand Down

0 comments on commit 8bf77cd

Please sign in to comment.