0

I have model call Report:

class Report(models.Model):
    owner = models.ForeignKey(User, related_name='report_owner')
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

How do I find out what the object_id of my models in all my apps are?

Shezan Kazi
  • 4,471
  • 3
  • 14
  • 27
  • Possible duplicate of [Get django object id based on model attribute](https://stackoverflow.com/questions/4659360/get-django-object-id-based-on-model-attribute) – aliva May 27 '17 at 11:33
  • I don't see how as my question deals with ContentType and not model fields. – Shezan Kazi May 27 '17 at 14:34

1 Answers1

2

so I found the answer in the docs.

 from django.contrib.contenttypes.models import ContentType
my_model = ContentType.objects.get(app_label='myapp', model='mymodel')

Then

my_model.id

returns the object_id.

Shezan Kazi
  • 4,471
  • 3
  • 14
  • 27