Thursday, July 26, 2018

Re: How to install django if user is using spyder

First - please don't hijack another topic; rather start your own.

Second - Django recommends you use pip inside a virtualenv (for development); see:
https://docs.djangoproject.com/en/2.0/topics/install/#installing-an-official-release-with-pip


On Tuesday, 24 July 2018 15:33:16 UTC+2, Akhil Reddy wrote:
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.

--
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+unsubscribe@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/a2a1be1a-41d4-4621-9414-5424b080f7ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment