1

I have the following models:

class User(models.Model):
    name = models.CharField(max_length=50, unique=True)

class RestrictedPermission(models.Model):
    name = models.CharField(max_length=50)
    user = ForeignKey(User)
    content_type = ForeignKey(ContentType)
    object_id = models.CharField(max_length=50)
    content_object = GenericForeignKey('content_type', 'object_id')

class DummyModel(models.Model):
    name = models.CharField(max_length=50)
    rest_perms = GenericRelation(RestrictedPermission)

I am trying to do a query on the DummyModel table such that the retrieved instances have certain RestrictedPermissions for a particular User, i.e. something like

DummyModel.objects.filter(rest_perms__user=user)

This seems to be failing because of known issues with the casting done by Django's ORM (https://stackoverflow.com/a/16051458/1560330). However, I am not sure how I can adapt the solutions presented there to my problem. Is this even the best way to do this type of query?

The exact error I get is

No operator matches the given name and argument type(s). You might need to add explicit type casts.

Any help would be greatly appreciated.

Edit: I am using Django 1.7 and python 2.7.

Community
  • 1
  • 1
gos1
  • 360
  • 5
  • 10

0 Answers0