не отображается в шаблоне?
#models
class Add(models.Model):
title = models.CharField('text', max_length=100)
body = models.TextField('Description')
class Computer(models.Model):
add = models.ForeignKey(Add, on_delete=models.CASCADE)
price = models.CharField('Цена', max_length=1000)
#forms
class AddForm(forms.ModelForm):
class Meta:
model = Add
fields = ('body', 'title')
class ComputerForm(forms.ModelForm):
class Meta:
model = Computer
fields = ('price',)
#views
def create_post(request):
if request.method == 'POST':
add_form = AddForm(request.POST)
computer_form = ComputerForm(request.POST)
if add_form.is_valid() and computer_form.is_valid():
addform = add_form.save()
computerform = computer_form.save(commit=False)
computerform.add = addform
computerform.save()
return redirect('/')
else:
add_form = AddForm()
computer_form = ComputerForm()
return render(request, 'posts/post_create.html', context={'addFrom': add_form, 'computerForm': computer_form})
#template
<form action="" method="post">
{% csrf_token %}
{{addForm.as_ul}}
{{computerForm.as_ul}}
<button type="submit">saveee</button>
</form>
dpaste.de github gist
как этим пользоваться?
Стикер
Обсуждают сегодня