Answer the question
In order to leave comments, you need to log in
How to bind post authors (in mini blogs) in django models?
In general, there is a post model:
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=255)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post-detail', args=[str(self.id)])
def publish(self):
self.published_date = timezone.now()
self.save()
class Meta:
ordering = ['published_date']
Answer the question
In order to leave comments, you need to log in
As an option to inherit from the User model and add ManyToManyField to itself
сlass CustomUser(User):
preferred_author = models.ManyToManyField('self', symmetrical=False, related_name='preferred', ...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question