blogapp
- added published flag to blogentry - added commenting func to blog posts - minor stuff
This commit is contained in:
parent
f168be2044
commit
833e19a3cc
|
@ -11,7 +11,7 @@ class blogentry(models.Model):
|
||||||
|
|
||||||
class blogcomment(models.Model):
|
class blogcomment(models.Model):
|
||||||
blogentry = models.ForeignKey(blogentry, on_delete=models.CASCADE)
|
blogentry = models.ForeignKey(blogentry, on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User, null = True)
|
||||||
guestname = models.CharField(max_length=20)
|
guestname = models.CharField(max_length=20)
|
||||||
body = models.CharField(max_length=300)
|
body = models.CharField(max_length=300)
|
||||||
date = models.DateTimeField('date')
|
date = models.DateTimeField('date')
|
||||||
|
|
|
@ -12,17 +12,36 @@
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
|
|
||||||
|
|
||||||
|
<b>Comments total: {{blogentry.blogcomment_set.all.count}}</b><br/>
|
||||||
|
|
||||||
|
{% if commentform %}
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
Your Name:<br>
|
||||||
|
{{ commentform.guestname }}
|
||||||
|
<br/>Your Comment:<br/>
|
||||||
|
{{ commentform.blogcomment }}<br>
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for comment in blogentry.blogcomment_set.all %}
|
||||||
|
{% if comment.user %}
|
||||||
|
<h3>{{ comment.user.username }} says:</h3>
|
||||||
|
{% else %}
|
||||||
|
<h3>{{ comment.guestname }} says:</h3>
|
||||||
|
{% endif %}
|
||||||
|
{{ comment.body|linebreaks }}<br/>
|
||||||
|
<small>{{ comment.date }}</small>
|
||||||
|
{% endfor %}
|
||||||
{% if false %}
|
{% if false %}
|
||||||
<b>Comments total: {{newsentry.newscomment_set.all.count}}</b><br/>
|
|
||||||
{% for newscomment in newsentry.newscomment_set.all %}
|
|
||||||
<table class="forumentry">
|
<table class="forumentry">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="border-top:1px; width: 80px; solid #b2c9d5;"><img src="/polylux/{{ newscomment.user.get_profile.getImage }}"></img></td>
|
<td align="center" style="border-top:1px; width: 80px; solid #b2c9d5;"><img src="/polylux/{{ newscomment.user.get_profile.getImage }}"></img></td>
|
||||||
<td style="border-top:1px solid #b2c9d5;"><br/><a href="/blackmesa/usermanager/detail/{{newscomment.user.id}}/">{{newscomment.user.username}}</a><br>{{ newscomment.commenttext|linebreaks|urlize }}<br/><small>Datum: {{newscomment.date}}</small></td>
|
<td style="border-top:1px solid #b2c9d5;"><br/><a href="/blackmesa/usermanager/detail/{{newscomment.user.id}}/">{{newscomment.user.username}}</a><br>{{ newscomment.commenttext|linebreaks|urlize }}<br/><small>Datum: {{newscomment.date}}</small></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<table
|
<table
|
||||||
style="text-align: left; width: 75%; margin-left: auto; margin-right: auto;"
|
style="text-align: left; width: 75%; margin-left: auto; margin-right: auto;"
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
{% autoescape off %}
|
{% autoescape off %}
|
||||||
{% if blogentries %}
|
{% if blogentries %}
|
||||||
{% for blogentry in blogentries %}
|
{% for blogentry in blogentries %}
|
||||||
|
{% if blogentry.published %}
|
||||||
<h1>{{ blogentry.header }}</h1>
|
<h1>{{ blogentry.header }}</h1>
|
||||||
<small>posted on: {{blogentry.date}} by {{blogentry.user.username}}</small>
|
<small>posted on: {{blogentry.date}} by {{blogentry.user.username}}</small>
|
||||||
<p>{{blogentry.intro|linebreaks}}</p><a href="{% url 'detail' blogentry.id %}">Read more...</a><br/>
|
<p>{{blogentry.intro|linebreaks}}</p><a href="{% url 'detail' blogentry.id %}">Read more...</a><br/>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No entries are available.</p>
|
<p>No entries are available.</p>
|
||||||
|
|
|
@ -5,7 +5,8 @@ from django import forms
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class BlogCommentForm(forms.Form):
|
class BlogCommentForm(forms.Form):
|
||||||
blogcomment = forms.CharField(widget=forms.Textarea(attrs={'rows':3, 'cols':30}))
|
guestname = forms.CharField()
|
||||||
|
blogcomment = forms.CharField(widget=forms.Textarea(attrs={'rows':3, 'cols':30}))
|
||||||
|
|
||||||
|
|
||||||
def listall(request):
|
def listall(request):
|
||||||
|
@ -13,13 +14,14 @@ def listall(request):
|
||||||
return render_to_response('blogapp/blogindex.html', {'blogentries': listall_entries}, context_instance=RequestContext(request))
|
return render_to_response('blogapp/blogindex.html', {'blogentries': listall_entries}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
def detail(request, blogentry_id):
|
def detail(request, blogentry_id):
|
||||||
blogdetail = get_object_or_404(blogentry, pk=blogentry_id)
|
blogdetail = get_object_or_404(blogentry, pk=blogentry_id)
|
||||||
|
|
||||||
form = BlogCommentForm()
|
form = BlogCommentForm()
|
||||||
if request.user.is_authenticated():
|
return render_to_response('blogapp/blogdetail.html', {'blogentry': blogdetail, 'commentform': form}, context_instance=RequestContext(request))
|
||||||
return render_to_response('blogapp/blogdetail.html', {'blogentry': blogdetail, 'commentform': form}, context_instance=RequestContext(request))
|
#if request.user.is_authenticated():
|
||||||
else:
|
# return render_to_response('blogapp/blogdetail.html', {'blogentry': blogdetail, 'commentform': form}, context_instance=RequestContext(request))
|
||||||
return render_to_response('blogapp/blogdetail.html', {'blogentry': blogdetail}, context_instance=RequestContext(request))
|
#else:
|
||||||
|
# return render_to_response('blogapp/blogdetail.html', {'blogentry': blogdetail}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
#def addarticle(request):
|
#def addarticle(request):
|
||||||
# if not request.user.is_staff:
|
# if not request.user.is_staff:
|
||||||
|
|
|
@ -23,5 +23,5 @@ urlpatterns = [
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
url(r'^about/', aboutpage, name='about'),
|
url(r'^about/', aboutpage, name='about'),
|
||||||
url(r'^contact/', contactpage, name='contact'),
|
url(r'^contact/', contactpage, name='contact'),
|
||||||
url(r'^', listall),
|
# url(r'^', listall),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue