Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django FieldError: Unsupported lookup 'kategorie' for IntegerField or join on the field not permitted

I have a Django Table with Crispy Filter and I would like to filter in Data table based on Category. But I am getting FieldError.

I tried to define my filter field by this way in filters.py:

kategorie = django_filters.CharFilter(label="Kategorie", field_name="ucet__cislo__kategorie__jmeno", lookup_expr='icontains')

And I have following structure of models in models.py:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Data(models.Model):
    ucet = models.ForeignKey(Ucty, on_delete=models.CASCADE, null=True, blank=True)

class Ucty(models.Model):
    cislo = models.IntegerField("Účet", blank=True, null=True)

class Mustek(models.Model):
    ucet = models.ForeignKey(Ucty, on_delete=models.CASCADE)
    kategorie = models.ForeignKey(Kategorie, on_delete=models.CASCADE)

class Kategorie(models.Model):
    jmeno = models.CharField("Kategorie", max_length=20, blank=True, null=True)


Any idea how to correct field_name definition in filter?

>Solution :

Since cislo is an IntegerField, you can not join on this. you probably want to join on Mustek in reverse however, so:

kategorie = django_filters.CharFilter(
    label='Kategorie',
    field_name='ucet__mustek__kategorie__jmeno',
    lookup_expr='icontains',
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading