Re: How to install django if user is using spyder

34 views
Skip to first unread message

Akhil Reddy

unread,
Jul 24, 2018, 9:33:16 AM7/24/18
to django...@googlegroups.com
Hello guys
    I'm using spyder it contain python 3.6 so how I can I install django
Please help me

On Tue 24 Jul, 2018 6:46 pm John Son, <john...@oakhillschool.net> wrote:
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...@googlegroups.com.
To post to this group, send email to django...@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.

Derek

unread,
Jul 26, 2018, 10:43:10 AM7/26/18
to Django users
First - please don't hijack another topic; rather start your own.

Second - Django recommends you use pip inside a virtualenv (for development); see:
Reply all
Reply to author
Forward
0 new messages