Hi @timonweb !
Thank you for your answer, but it doesn’t really work (well, it is just that I don’t know how to resolve the following issue). When I try to
python manage.py makemigrations
I obtain :
You are trying to add a non-nullable field 'slugs_ptr' to forum without a default; we can't do that (the database needs something to populate existing rows)
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Here is my code updated :
class Slugs(models.Model):
model_name_raw = models.CharField(max_length=40, default=None)
model_name_slug = models.SlugField(max_length=80, default=None, blank=True)
def save(self, *args, **kwargs):
self.model_name_slug = slugify(self.model_name_raw)
super().save(*args, **kwargs)
def __str__(self):
return self.model_name_raw
# Create your models here.
class Forum(Slugs):
forum_description = models.CharField(max_length=100)
class Topic(Slugs):
topic_forum = models.ForeignKey(Forum, related_name="topic_forum", on_delete=models.CASCADE)
topic_description = models.CharField(max_length=100)
topic_author = models.ForeignKey(User, related_name="topic_author", on_delete=models.CASCADE)
topic_answers = models.IntegerField(default=0)
topic_last_answer_by = models.ForeignKey(User,related_name="topic_last_answer_by",on_delete=models.CASCADE)