I have two model post and HeaderImage. I want use both of model in my html froms. here is my code:
models.py
class Post(models.Model):
title = models.CharField(max_length=300,unique=True,error_messages={'unique':"This title already exists. Please use different title"})
author = models.ForeignKey(User, on_delete=models.CASCADE)
class HeaderImage(models.Model):
header_image = models.ImageField() #I want to merge this model with Post model and want to add image field in my current forms.
froms.py
class BlogPost(forms.ModelForm):
class Meta:
model = Post
fields = ['title','author','body']
views.py
class BlogUpdateView(PermissionRequiredMixin,UpdateView):
raise_exception = True
permission_required = "blog.change_post"
model = Post
template_name = "blog_update_post.html"
form_class = BlogPost
How to get image filed from second model and add it to existing from which using first model?