Answer the question
In order to leave comments, you need to log in
How to pass the url of the page from which the request was sent to the hidden field of the form (ModelForm)?
Input data:
models
class User_information(models.Model):
name = models.CharField(max_length=50)
second_name = models.CharField(max_length=50)
phone = PhoneNumberField()
email = models.EmailField()
url = models.SlugField()
class PostForm(ModelForm):
class Meta:
model = User_information
fields = ['name', 'second_name', 'phone', 'email', 'url']
labels = {
'name': _('Имя'),
'second_name': _('Фамилия'),
'phone': _('Телефон'),
'email': _('EMAIL'),
}
widgets = {
'name': Textarea(attrs={'cols': 80, 'rows': 3}),
# 'url' : HiddenInput(), как добавить виджет скрытого поля
}
def detail(request, slug):
html = 'post_detail.html'
categories = Category.objects.all()
query_set = get_object_or_404(Post, slug=slug)
form = PostForm(request.POST or None)
if form.is_valid():
name = form.cleaned_data['name']
second_name = form.cleaned_data['second_name']
phone = form.cleaned_data['phone']
email = form.cleaned_data['email']
query_set = form.save(commit=False)
query_set.save()
# send_mail(name)
form = PostForm()
print(name, second_name, phone, email)
context = {
'detail': query_set,
'categories': categories,
"form": form,
}
return render(request, html, context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question