0
In models.py
created the following tables:
class UsuarioAdicionalPlano(models.Model):
quantidade = models.PositiveIntegerField(primary_key=True)
preco = models.DecimalField(decimal_places=2, max_digits=13)
class ConfiguracoesDoPlano(models.Model):
plano = models.ForeignKey('login.Plano', related_name='plano', on_delete=models.CASCADE)
usuarios_adicional = models.ForeignKey('login.UsuarioAdicionalPlano', related_name='usuario_adicional', on_delete=models.CASCADE)
In forms.py
class ConfiguracoesDoPlanoForm(forms.ModelForm):
class Meta:
model = ConfiguracoesDoPlano
fields = ('plano', 'notas_adicional', 'usuarios_adicional')
widgets = {
'plano': forms.Select(attrs={'class': 'form-control'}),
'usuarios_adicional': forms.Select(attrs={'class': 'form-control'}),
}
labels = {
'plano': 'Plano escolhido',
'usuarios_adicional': 'Usuários adicionais',
}
And in the archive .html
I have the following Select
The form
comes from ConfiguracoesDoPlanoForm
table ConfiguracoesDoPlano
<div class="form-group">
<label>{{form.usuarios_adicional.label}}</label><strong style="color:red;"> *</strong>
{% if form.usuarios_adicional.errors %}<label class="error">{% for error in form.usuarios_adicional.errors %}{{error}}{% endfor %}</label>{% endif %}
<div class="input-group" style="margin-bottom: 0px;">
<div class="form-line">
{{form.usuarios_adicional}}
</div>
</div>
</div>
But mine select
is appearing with the values 'UsuarioAdicionalPlano object (0)'
, 'UsuarioAdicionalPlano object (1)'
, and so on.
How do I make the values of the Select
is the value of the attribute quantidade
?
Worked using the function
def __str__(self): return str(self.quantidade)
– Rafael