Context: Mac OS X 10.7.5, Django 1.5.4
In a multidatabase project (two databases':default' and 'noe') I have the 
following model in 'default' database

class MovimentoOrdineDettaglio(models.Model):
    id_ordine = models.ForeignKey(MovimentoOrdine,db_column='id_ordine')
    codarticolo = models.ForeignKey(ArticoliLista, 
db_index=True,verbose_name='Articolo')
    numerounita = 
models.IntegerField(db_column='NumeroUnita',blank=True,default=0,
                       verbose_name=u'Numero Unità')

and the following in 'noe' database

class specifica_noe(models.Model):
    nome_db = 'noe'
    id_ordine = models.ForeignKey(ordini_magazzino, db_column='ID_ORDINE', 
to_field='id_ordine')
    cod_magazzino_ext = models.CharField(max_length=48, 
db_column='COD_MAGAZZINO_EXT')
    qta = models.IntegerField(null=False, blank=False, db_column='QTA')
    def __unicode__(self):
        return u"%s art. %s" % (self.id_ordine, self.cod_magazzino_ext)



I draw your attention on field 'id_ordine' and 'codarticolo' of model 
MovimentoOrdineDettaglio which are connected via foreign keys to a model 
MovimentoOrdine and ArticoliLista also in 'default' database.
I'm trying to load records using data from model specifica_noe in 'noe' 
database by means of a loop intoMovimentoOrdineDettaglio in 'default' . In 
doing so I create the instances art and ord (see below) to take into account 
the ForeignKey fields. I've introduced two print commands to check if 
everything is ok.

Here it is a snippet of my shell session.

-----------------------
>>> det = specifica_noe.objects.all()
>>> #
>>> for d in det:
...     art = ArticoliLista.objects.get(codice=d.cod_magazzino_ext)
...     ord = MovimentoOrdine.objects.get(id_ordine=d.id_ordine_id)
...     if not 
MovimentoOrdineDettaglio.objects.filter(id_ordine=d.id_ordine_id,  
codarticolo=d.cod_magazzino_ext):
...         print("Order %s for article %s does not exist-load now") % 
(d.id_ordine_id,d.cod_magazzino_ext)
...         rec = MovimentoOrdineDettaglio(id_ordine=ord, 
codarticolo=art,numerounita=d.qta)
...         print('%s %s %s') % (rec.id_ordine,rec.codarticolo,rec.numerounita)
...         rec.save()
... #
... 
Order 1 for article 0005201 does not exist-load now
Ord.1 per BONAPARTE NAPOLEONE ABBA*12BUST 875MG+125MG 10
Order 1 for article MAS105 does not exist-load now
Ord.1 per BONAPARTE NAPOLEONE ACTISORB 10,5X10,5CM 5
Order 3 for article 0000004 does not exist-load now
Ord.3 per MANZONI ALESSANDRO ADALAT CRONO 30MG 14 CPR RIV. 7
Order 3 for article 0060000140 does not exist-load now
Ord.3 per MANZONI ALESSANDRO ACQUA OSSIGENATA 10VOL 1000ML 1
Order 2 for article 0005201 does not exist-load now
Ord.2 per CESARE GIULIO ABBA*12BUST 875MG+125MG 8
Order 6 for article 0060000140 does not exist-load now
Ord.6 per MANZONI ALESSANDRO ACQUA OSSIGENATA 10VOL 1000ML 2
Order 5 for article MAS105 does not exist-load now
Ord.5 per LINCOLN ABRAMO ACTISORB 10,5X10,5CM 15
Order 5 for article MAS190 does not exist-load now
Ord.5 per LINCOLN ABRAMO ACTISORB 10,5X19 12
Order 4 for article 8016629001115 does not exist-load now
Ord.4 per EINAUDI LUIGI ABBASSALINGUA IN LEGNO DOC N/ST CF.100 25
>>> 
-----------------------

Everything seems ok
for instance, just to doublecheck, for the last rec of the loop I have
>>> rec.id_ordine
<MovimentoOrdine: Ord.4 per EINAUDI LUIGI>
>>> rec.codarticolo
<ArticoliLista: ABBASSALINGUA IN LEGNO DOC N/ST CF.100>
>>> rec.numerounita
25
>>>

BUT.... if I issue:

>>> f=MovimentoOrdineDettaglio.objects.all()
>>> f
[]

No records at all in the table!
Nothing anomalous is signalled by python/django.

Help please.
Ciao from Rome
Vittorio


-- 
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 [email protected].
To post to this group, send email to [email protected].
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/609C9977-68D5-4909-AFBD-5D0C4D5DB8B9%40de-martino.it.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to