**FIXED**

>
> #public_posts/forms/py
>
> from django.forms import ModelForm
>
> from .models import PublicPost
>
> class PublicPostForm(ModelForm):
>
>     class Meta:
>         model = PublicPost
>         fields = ('title', 'text') #didn't need author
>
>
>
>
> # public_posts/views.py
>
>
>
> from django.shortcuts import render
> from django.utils import timezone
> from .models import PublicPost
> from django.urls import reverse_lazy
> from django.views import generic
> from django.http import HttpResponseRedirect
> from django.shortcuts import render, redirect
> from . import forms
> from django.forms import ModelForm as Form
>
>
> def pub_post_list(request):
>    
>     posts = 
> PublicPost.objects.filter(published_date__lte=datetime.now()).order_by('published_date')
>  
> <== Changed
>
>     return render(request, 'public_posts/pub_posts.html', {'posts': posts})
>
> def post_new(request):
>     if request.method == 'POST':
>         form = forms.PublicPostForm(request.POST)
>         if form.is_valid():
>             content = form.save(commit=False)
>             content.author = request.user
>             content.save()
>             return redirect('pub_posts')
>     else:
>         form = forms.PublicPostForm()
>     return render(request, 'public_posts/new_post.html', {'form': form})
>
>
>
>
>
> # public_posts/models.py
>
> from django.conf import settings
> from django.db import models
> from django.utils import timezone
> from django.utils.http import urlquote
> from django.utils.translation import ugettext_lazy as _
> from django.core.mail import send_mail
> from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
> from django.contrib.auth.models import BaseUserManager
> from django.contrib.auth import get_user_model
> User = get_user_model()
>
> # Create your models here.
> class PublicPost(models.Model):
>     author = models.ForeignKey(User, related_name='pub_poster', 
> on_delete=models.CASCADE, null=True)
>     title = models.CharField(max_length=200)
>     text = models.TextField()
>     created_date = models.DateTimeField(default=timezone.now)
>     published_date = models.DateTimeField(auto_now=True, null=True) <== 
> Changed
>
>
>     def publish(self):
>         self.published_date = published_date <== Changed
>         self.save()
>
>     def __str__(self):
>         return self.title
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/709074e3-964e-4c02-8b6f-d119284ffbc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to