Answer the question
In order to leave comments, you need to log in
Where is the error in Django form data edit function?
I'm trying to edit the data that is saved through the ModelForm.
modelka
class Person(models.Model):
class Meta:
db_table = 'person'
author = models.ForeignKey(User, )
first_name = models.CharField( verbose_name="Имя", max_length=150, )
last_name = models.CharField(verbose_name="Фамилия", max_length=150, )
date_of_births = models.DateField( verbose_name="Дата рождения",max_length=10, )
timestamp = models.DateTimeField(verbose_name="Дата создания", auto_now_add=True, )
time_update = models.DateTimeField(verbose_name="Дата обновления",auto_now=True, )
class PersonForm(forms.ModelForm):
class Meta:
model = Person
fields = ( 'first_name', 'last_name', 'date_of_births', )
def edit_person(request, person_id):
person = get_list_or_404(Person, id=person_id)
if request.method == "POST":
person_form = PersonForm(request.POST, instance=person)
if person_form.is_valid():
person_f = person_form.save(commit=False)
person_f.author = request.user
person_f.save()
messages.success(request, "Запись в базе данных обновлена!")
return redirect('/')
else:
person_form = PersonForm(instance=Person)
context = { 'person_form': person_form,}
return render(request, 'anketa/edit_person.html', context)
urlpatterns = [
...
url(r'^(?P<person_id>\d+)/edit/$', a_views.edit_person, name='edit_person'),
...
]
AttributeError: 'list' object has no attribute '_meta'
Answer the question
In order to leave comments, you need to log in
https://jsfiddle.net/webirus/stycx5y3/
.block {
width: 100px;
height: 100px;
line-height: 100px;
margin-left: 100px;
border: 2px solid #000;
}
.block span {
position: relative;
margin-left: -50px;
font-size: 50px;
background: #FFF;
}
codepen.io/ruslanredo/pen/jmObGp
div{
border:4px solid black;
width:200px;
height:200px;
position:relative;
}
div:before{
content:"2009";
position:absolute;
font-size:80px;
background:white;
left:-20px;
top:55px;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question