I have models:
models.py
class CommentCollection(models.Model):
name = models.CharField(max_length=50)
class Comment(models.Model):
comments_collection = models.ForeignKey(CommentCollection, related_name='comments', on_delete=models.CASCADE)
reply_to = models.ForeignKey('self', related_name='replies', null=True, blank=True, on_delete=models.CASCADE)
text = models.TextField()
user = models.ForeignKey(User, related_name='user_comments', on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
is_public = models.BooleanField(default=False, verbose_name='Published')
<admin.py>
@admin.register(CommentCollection)
class CommentCollectionAdmin(admin.ModelAdmin):
list_display = ['id', 'name']
How to make it so that: When adding a new comment via the admin panel, after filling in the "comments_collection" field (selection from the CommentCollection model), only those comments that belong to the same collection of comments are displayed in the reply_to field for selection.
@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ('comments_collection', 'user', 'created', 'is_public')