OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Image upload in CreateView

  • Thread starter Thread starter user11040244
  • Start date Start date
U

user11040244

Guest
I have a CreateView in my project to post a tweet-like-post. It has a title and content. It look like this in views.py

Code:
class PostCreateView(LoginRequiredMixin, CreateView):
    model = Post
    fields = ['title', 'content']


    def form_valid(self, form):  # Author for post (required- if no- error)
        form.instance.author = self.request.user
        return super().form_valid(form)

And I would like to add picture-upload column to make a persons able to upload a picture with the post.

My models.py looks like this

Code:
class Post(models.Model):
    title = models.CharField(max_length=100, verbose_name='タイトル')
    content = models.TextField(verbose_name='内容')
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title
    def get_absolute_url(self):
        return reverse('Post-detail', kwargs={'pk': self.pk})

I already have a uploaded_pic folder in my static with 777 permision. Could you please tell me how to add there working picture-upload column
<p>I have a <code>CreateView</code> in my project to post a tweet-like-post. It has a title and content.
It look like this in views.py</p>

<pre class="lang-py prettyprint-override"><code>class PostCreateView(LoginRequiredMixin, CreateView):
model = Post
fields = ['title', 'content']


def form_valid(self, form): # Author for post (required- if no- error)
form.instance.author = self.request.user
return super().form_valid(form)
</code></pre>

<p>And I would like to add <code>picture-upload</code> column to make a persons able to upload a picture with the post.</p>

<p>My models.py looks like this</p>

<pre class="lang-py prettyprint-override"><code>class Post(models.Model):
title = models.CharField(max_length=100, verbose_name='タイトル')
content = models.TextField(verbose_name='内容')
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)

def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('Post-detail', kwargs={'pk': self.pk})
</code></pre>

<p>I already have a <code>uploaded_pic</code> folder in my <code>static</code> with 777 permision.
Could you please tell me how to add there working <code>picture-upload</code> column</p>
 

Latest posts

Z
Replies
0
Views
1
zuegelwagen
Z
Top