Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. {% extends "blog/base.html" %}
  2. {% block body_block %}
  3.  
  4.  
  5. <div class="left">
  6. {% if userposts %}
  7. {% for posts in userposts %}
  8. <div class="front-post">
  9. <h2 class="post-title">{{ posts.post_title }}</h2>
  10. <h3 class="post-sub-title">{{ posts.post_sub_title }}</h3>
  11. <p class="post-author">{{ post.post_author }}</p>
  12. <p class="post-date">{{ post.post_date }}</p>
  13. <p class="post-body">{{ post.post_body }}</p>
  14. </div>
  15. {% endfor %}
  16. {% endif %}
  17. </div>
  18.  
  19.  
  20. <div class="right">
  21. <p>SIDE BAR</p>
  22. </div>
  23.  
  24.  
  25. {% endblock %}
  26.  
  27. from django.shortcuts import render
  28. from blog.forms import UserForm,UserProfileInfoForm,AddPost
  29. from blog.models import UserPosts
  30.  
  31. from django.contrib.auth import authenticate,login,logout
  32. from django.http import HttpResponseRedirect,HttpResponse
  33. from django.core.urlresolvers import reverse
  34. from django.contrib.auth.decorators import login_required
  35.  
  36. # Create your views here.
  37. def index(request):
  38. post_list = UserPosts.objects.order_by('post_date')
  39. post_dict = {'userposts':post_list}
  40.  
  41. return render(request, 'blog/index.html',context=post_dict)
  42.  
  43. from django.db import models
  44. from django.contrib.auth.models import User
  45.  
  46. # Create your models here.
  47. class UserProfileInfo(models.Model):
  48. user = models.OneToOneField(User)
  49.  
  50. portfolio_site = models.URLField(blank=True)
  51. profile_pic = models.ImageField(upload_to='profile_pics',blank='True')
  52.  
  53. def __str__(self):
  54. return self.user.username
  55.  
  56.  
  57. class UserPosts(models.Model):
  58. post_title = models.CharField(max_length=100,unique=True)
  59. post_sub_title = models.CharField(max_length=250,unique=False)
  60. post_author = ''
  61. post_date = models.DateField(auto_now=True)
  62. post_body = models.TextField(max_length=1000,unique=False)
  63.  
  64. def __str__(self):
  65. return str(self.post_title)
  66.  
  67. from django import forms
  68. from django.contrib.auth.models import User
  69. from blog.models import UserProfileInfo,UserPosts
  70.  
  71. class UserForm(forms.ModelForm):
  72. password = forms.CharField(widget=forms.PasswordInput())
  73.  
  74. class Meta():
  75. model = User
  76. fields = ('username','email','password')
  77.  
  78. class UserProfileInfoForm(forms.ModelForm):
  79. class Meta():
  80. model = UserProfileInfo
  81. fields = ('portfolio_site','profile_pic')
  82.  
  83. class AddPost(forms.ModelForm):
  84. class Meta():
  85. model = UserPosts
  86. fields = '__all__'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement