Add recipient list to comment section

This commit is contained in:
Nathan Chapman 2022-07-22 14:33:30 -06:00
parent 08abb25ce8
commit 1d688a4123
2 changed files with 16 additions and 1 deletions

View File

@ -130,7 +130,8 @@ class Post(models.Model):
recipients = models.ManyToManyField( recipients = models.ManyToManyField(
User, User,
blank=True, blank=True,
related_name='subscriptions' related_name='subscriptions',
help_text='will be notified when creating or commenting on a post'
) )
tags = GenericRelation(Tag) tags = GenericRelation(Tag)

View File

@ -51,6 +51,20 @@
<form action="{% url 'core:comment-create' %}" method="POST"> <form action="{% url 'core:comment-create' %}" method="POST">
{% csrf_token %} {% csrf_token %}
{{ comment_create_form.as_p }} {{ comment_create_form.as_p }}
<p>
{% for recipient in post.recipients.all %}
{% if post.recipients.all|length > 2 %}
{% if not forloop.last %}{{ recipient }},{% else %}and {{ recipient }}{% endif %}
{% elif post.recipients.all|length is 2 %}
{% if forloop.last %}and {{ recipient }} {% else %} {{ recipient }}{% endif %}
{% else %}
{{ recipient }}
{% endif %}
{% empty %}
No one
{% endfor %}
will be notified when you post your comment.
</p>
<input class="action-button" type="submit" value="Post comment"> <input class="action-button" type="submit" value="Post comment">
</form> </form>
</div> </div>