*models.py*
class Post(models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, 
null=True)
    date = models.DateField(default=datetime.now, blank=True)
    text_author = models.CharField(max_length=200, null=True, blank=True)

*forms.py*
class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ("title", "body", "user", "text_author")
*views.py*
def create_Post(request):
    form = PostForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        return HttpResponseRedirect (instance.get_absolute_url())
    context = {
        "form": form,
    }
    return render(request, 'blog/create.html', context)

*As shown in attached image, the user has to select themselves from list of 
users before they can submit their post.(which doesn't make sense). I want 
the form to know which user is writing the form(assuming they are logged 
in) so the user doesn't have to identify themselves before they submit 
their post. I'm guessing I need to edit my models.py but I have no idea. 
Please Help.*

*Thank you.*

-- 
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/75d197ab-503c-4aed-83ce-210831fb1502%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to