Форум сайта python.su
имеются следующие модели
class template_people(models.Model):
name = models.CharField(max_length=255, verbose_name=u'Имя')
lastname = models.CharField(max_length=255, verbose_name=u'Фамилия')
fathername = models.CharField(max_length=255, verbose_name=u'Отчество')
class Meta:
abstract = True
class People1(template_people):
def __unicode__(self):
return u'%s %s %s [id: %s]' % (self.lastname, self.name, self.fathername, self.id)
class Meta:
verbose_name_plural = "People1"
class People2(template_people):
def __unicode__(self):
return u'%s %s %s [id: %s]' % (self.lastname, self.name, self.fathername, self.id)
class Meta:
verbose_name_plural = "People2"
class People1Form(forms.ModelForm):
class Meta:
model = People1
class People2Form(forms.ModelForm):
class Meta:
model = People2
<form action="" method="post">
<table>
<TR><TD><br> <b>people1</b> </TD></TR>
<tr><th><label for="id_name">Имя:</label></th><td><input id="id_name" type="text" name="name" maxlength="255" /></td></tr>
<tr><th><label for="id_lastname">Фамилия:</label></th><td><input id="id_lastname" type="text" name="lastname" maxlength="255" /></td></tr>
<tr><th><label for="id_fathername">Отчество:</label></th><td><input id="id_fathername" type="text" name="fathername" maxlength="255" /></td></tr>
<TR><TD><br> <b>people2</b> </TD></TR>
<tr><th><label for="id_name">Имя:</label></th><td><input id="id_name" type="text" name="name" maxlength="255" /></td></tr>
<tr><th><label for="id_lastname">Фамилия:</label></th><td><input id="id_lastname" type="text" name="lastname" maxlength="255" /></td></tr>
<tr><th><label for="id_fathername">Отчество:</label></th><td><input id="id_fathername" type="text" name="fathername" maxlength="255" /></td></tr>
</table>
<input type="submit" value="Сохранить">
</form>
Отредактировано (Сен. 10, 2009 08:49:23)
Офлайн
пробовал так, не помогает :(
class People1Form(forms.ModelForm):
class Meta:
model = People1
def __init__(self, *args, **kwargs):
super(People1Form, self).__init__(*args, ** kwargs)
self.fields['name'].widget=(forms.TextInput(attrs={'name':'People1Form_name'}))
Офлайн
хы, можно так изменить :)
class People1Form(forms.ModelForm):
class Meta:
model = People1
def __init__(self, *args, **kwargs):
super(People1Form, self).__init__(*args, ** kwargs)
name_var = self.fields.get('name')
self.fields['people1form_name'] = name_var
self.fields.pop('name')
lastname_var = self.fields.get('lastname')
self.fields['people1form_lastname'] = lastname_var
self.fields.pop('lastname')
fathername_var = self.fields.get('fathername')
self.fields['people1form_fathername'] = fathername_var
self.fields.pop('fathername')
class People2Form(forms.ModelForm):
class Meta:
model = People2
def __init__(self, *args, **kwargs):
super(People2Form, self).__init__(*args, ** kwargs)
name_var = self.fields.get('name')
self.fields['people2form_name'] = name_var
self.fields.pop('name')
lastname_var = self.fields.get('lastname')
self.fields['people2form_lastname'] = lastname_var
self.fields.pop('lastname')
fathername_var = self.fields.get('fathername')
self.fields['people2form_fathername'] = fathername_var
self.fields.pop('fathername')
class People1(models.Model):
name1 = models.CharField(max_length=255, verbose_name=u'Имя')
lastname1 = models.CharField(max_length=255, verbose_name=u'Фамилия')
fathername1 = models.CharField(max_length=255, verbose_name=u'Отчество')
class People2(models.Model):
name2 = models.CharField(max_length=255, verbose_name=u'Имя')
lastname2 = models.CharField(max_length=255, verbose_name=u'Фамилия')
fathername2 = models.CharField(max_length=255, verbose_name=u'Отчество')
Офлайн
Form.prefix
You can put several Django forms inside one <form> tag. To give each Form its own namespace, use the prefix keyword argument:
>> mother = PersonForm(prefix="mother")
>>> father = PersonForm(prefix="father")
>>> print mother.as_ul()
<li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" /></li>
<li><label for="id_mother-last_name">Last name:</label> <input type="text" name="mother-last_name" id="id_mother-last_name" /></li>
>>> print father.as_ul()
<li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name" /></li>
<li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name" /></li>
Офлайн
PooHвсе гениальное просто :)
Form.prefix
You can put several Django forms inside one <form> tag. To give each Form its own namespace, use the prefix keyword argument:
Офлайн