carltongibson/django-filter

AttributeError: type object '<model name> has no attribute '_meta'

yogeshchandrark opened this issue · 1 comments

Hi all,

i have below configs in my virtual env running on my Ubuntu 22.04 server

Django==4.2.5
Python==3.11.5
django-filter==23.3

settings.py

'DEFAULT_FILTER_BACKENDS': [
'django_filters.rest_framework.DjangoFilterBackend',
],

models.py

class Labroom_SpaceUtilisation(models.Model):
Tpname = models.CharField(max_length=150, unique=False, null=True, blank=True)
Program = models.CharField(max_length=150, unique=False, null=True, blank=True)
Labroom = models.CharField(max_length=150, unique=False, null=True, blank=True)
FreeSpace = models.CharField(max_length=150, unique=False, null=True, blank=True)
TotalSpace = models.CharField(max_length=150, unique=False, null=True, blank=True)

    def __int__(self):
        return self.id

   class Meta:
        ordering = ('id',)
        verbose_name_plural = "Lab Room Utilization"

filters.py

from django_filters import rest_framework as filters
from django_filters import FilterSet
from .models import Labroom_SpaceUtilisation

class LabroomFilters(FilterSet):
Tpname = filters.CharFilter('Tpname')
Program = filters.CharFilter('Program')
Labroom = filters.CharFilter('Labroom')

   class Meta:
         model = Labroom_spaceUtilisation
         fields = ['Tpname','Program','Labroom']

when i run the server i get the below error

AttributeError: type object 'Labroom_SpaceUtilisation' has no attribute '_meta'

what is the issue, is it issue with the version i have isntalled (compatibility issue ?)

Please help me with this

There's some problem with your models...

Labroom_SpaceUtilisation — I'd try following Python/Django's naming conventions to begin: LabroomSpaceUtilisation and tp_name, program etc.

Comment out the FilterSet and try loading your models in the Admin first.

This isn't really a Django-Filter issue, sorry. Good luck.