So I have a model Post with the following definition:
class Post(models.Model):
post_body = models.TextField()
user = models.ForeignKey(
to=User,
on_delete=models.CASCADE
)
published = models.BooleanField(
default=False
)
schedule = models.DateTimeField(
default=timezone.now
)
I have created a form in HTML template allowing the user to select the posts he want to send to another website or social media account. Like so:
<form>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Select</th>
<th scope="col">Post Body</th>
<th scope="col">Published?</th>
<th scope="col">Schedule (Editable)</th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr>
<td>
<div class="form-group">
<input type="checkbox" value="{{ post.id }}">
</div>
</td>
<td>{{ post.post_body }}</td>
<td>{{ post.published }}</td>
<td>
<div class="form-group">
<input type="datetime-local" class="form-control" name="schedule" value="{{ post.schedule|date:"Y-m-d\TH:i" }}">
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<button class="btn btn-primary" type="submit">Post</button>
</form>
I want to create a Form in the forms.py in order to process this information (i.e. know which all posts were selected) and then perform further actions (calling other APIs in order to publish these to other sites), also since the field schedule is editable, I want to be able to save that as well. Please help as I cannot think of a possible form for this.