[Django]-Django: AttributeError: type object 'GroupModel' has no attribute '_meta'

3👍

Models in Django need to be a subclass of the Model class [Django-doc]:

from django.db import models

class GroupModel(models.Model):
    title=models.CharField(max_length=20)
    description = models.CharField()

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'group'

Your __str__ should also return a string, so for example self.title, not self, since that is a GroupModel object, not a string.

1👍

Tip: In order to improve your code you don’t need to check if “is_valid()” is true or not. You could use “is_valid(raise_exception=True)” to raise a 400 error automatically if there is something wrong.

Leave a comment