Входные данные:
modelsclass 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()
formsclass 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(), как добавить виджет скрытого поля
}
Viewsdef 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)
Как автоматом подставлять в скрытое поле url страницы формы?
Как вывести url данной страницы во вьюху?