Monday, February 22, 2021

django.core.exceptions.FieldError: Related Field got invalid lookup: relation_type


Hi folks,

i implemetned the following models:

```python
class MetadataRelation(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
from_metadata = models.ForeignKey('Metadata', on_delete=models.CASCADE, related_name='from_metadatas')
to_metadata = models.ForeignKey('Metadata', on_delete=models.CASCADE, related_name='to_metadatas')
relation_type = models.CharField(max_length=255, null=True, blank=True,


class Metadata(Resource):
...
related_metadatas = models.ManyToManyField('self', through='MetadataRelation', symmetrical=False, related_name='related_to+', blank=True)
```

I want to filter a queryset of `Metadata` objects by the related field called `relation_type` like: `Metadata.objects.filter(
metadata_type=MetadataEnum.SERVICE.value,
is_active=True).exclude(related_metadatas__relation_type=MetadataRelationEnum.HARVESTED_THROUGH.value) django raises django.core.exceptions.FieldError: Related Field got invalid lookup: relation_type.

Why i can't use the related fields as filters if i use the through argument for the m2m field?


greetings

Jonas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/80e10688-94a5-407a-bd9f-6065f23e8224n%40googlegroups.com.

No comments:

Post a Comment