Thursday, January 16, 2014

save returns the id and pk none



my model


class Caixafaccao(models.Model):

    empresa = models.ForeignKey(Empresa, null=True, blank=True)
    cliente = models.ForeignKey(Cliente, verbose_name=u'Cliente')
    conta = models.ForeignKey(Conta, verbose_name=u'Conta' )
    subconta = models.ForeignKey(SubConta, verbose_name=u'Sub-Conta' )
    caixa = models.IntegerField(u'Caixa', blank=True, null=True)
    entrega = models.IntegerField(u'Entrega', blank=True, null=True)
    entregaitens = models.IntegerField(u'Entrega Itens', blank=True, null=True)
    dtlancamento = models.DateField(u'Data lançamento', default=datetime.now, null=True, blank=True)
    idcentrocusto = models.CharField(u'Centro de custo', max_length=1, default='', choices=Centro_custo_CHOICE)
    valor = models.DecimalField(u'Vlr. Unit.', max_digits=18, decimal_places=2, default=0)
    tipo = models.CharField(u'Tipo', max_length=1, default='', null=True, blank=True, choices=DebCred_CHOICE)
    observacoes = models.TextField(u'Observações', max_length=650, default='', null=True, blank=True)
    valordefeito = models.DecimalField(u'Vlr. Defeito.', default=0, max_digits=18, decimal_places=2, null=True, blank=True)


    class Meta:
        ordering = ['dtlancamento','id' ]

    def __unicode__(self):
       return u'%s' % (self.id)






my form


class CaixafaccaoForm(ModelForm):
    class Meta:
        model = Caixafaccao

    def __init__(self, *args, **kwargs):
        super( CaixafaccaoForm , self).__init__(*args, **kwargs)

        self.fields["dtlancamento"].widget.attrs['readonly'] = "True"
        self.fields["dtlancamento"].widget.attrs['class'] = "data"
        self.fields["cliente"].widget.attrs['class'] = "chosen-select-no-results"
        self.fields["observacoes"].widget.attrs['style'] = "width: 555px; height: 150px; resize: none;"
        self.fields["conta"].widget.attrs['class'] = "chosen-select-no-results"
        self.fields["subconta"].widget.attrs['class'] = "chosen-select-no-results"


    def __new__(cls, *args, **kwargs):
        new_class = super(CaixafaccaoForm, cls).__new__(cls, *args, **kwargs)
        for field in new_class.base_fields.values():
            if isinstance(field, DecimalField):
                field.localize = True
                field.widget.is_localized = True
        return new_class





My view code

 if request.method == 'POST':
            form_caixafaccao = CaixafaccaoForm(request.POST )
            if form_caixafaccao.is_valid():

                caixafaccao = form_caixafaccao.save( commit=False )



when I get the form_caixafaccao.save caixafaccao returns with id = PK = None and None debugging and saw that has an error DoesNotExist <class'movimento.models.DoesNotExist'> if someone can help me thank you.







--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22b329b9-19f0-446f-bf40-b57cd916bd73%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate