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 str
ing, so for example self.title
, not self
, since that is a GroupModel
object, not a str
ing.
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.
- [Django]-I deleted a css static file but my website still reads it?
- [Django]-How can I know if a specific user, not the current requesting user, is logged in Django?
Source:stackexchange.com