Need a second set of eyes on this. Cannot figure out why data is not going to the form.
template
{% extends 'base.html' %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<title>Document</title>
</head>
<body>
{% block body %}
<div class="container mt-2">
<form method="POST" >
{% csrf_token %}
<br><h1><center>Send Email</center></h1><br>
<center>{{ form.as_p }}</center>
</div><br><br>
<center><input type="submit" value="Send" style="background-color: rgb(8, 167, 8); color: white; height:38px; width:70px; padding-bottom: 6px;">
<a href="{% url 'index' %}" class="btn btn-danger">Cancel</button></a></center>
</div>
</form>
</div>
{% endblock body %}
</body>
</html>
form
class EmailNewForm(forms.ModelForm):
orginal_message = forms.CharField(max_length=500, widget=forms.Textarea, required=True, label='Email Message')
# m28t_sender = forms.CharField(max_length=50, disabled=True)
# m28t_receiver = forms.CharField(max_length=50, disabled=True)
class Meta:
model = M28tEmails
fields = ('m28t_sender',
'm28t_receiver',
'orginal_message',
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(kwargs, args, self.instance)
# m28t_sender = CustomUser.objects.filter(id=self.instance.id).values('id')
# self.fields['m28t_sender'] = m28t_sender
view
@login_required
def email_new(request, sponsor, id):
if request.method == "POST":
form = (request.POST)
if form.is_valid():
form.save()
# owner = CustomUser.objects.filter(pk=request.user.id).get()
# Organization.objects.filter(org_name=form.cleaned_data['org_name']).update(org_owner=owner.pk)
return render(request, 'index.html', {'form': form})
else:
form = EmailNewForm()
return render(request, "accounts/email_new_form.html", {'form': form})
url
path('email_new/<int:id>/<int:sponsor>/', views.email_new, name='accounts/email_new'),
output
{} () None, None, None, None, None, None
[06/Nov/2023 11:26:22] "GET /accounts/email_new/34/2/ HTTP/1.1" 200 5811
Ids are sent for receiver 34 and sponsor 2