On Apr 3, 3:31 pm, Imuvy <ivan.marches...@gmail.com> wrote:
> Dear Django Users
> I'm new to django and I'm creating my first django application.
> I'm using the development version
>
> I was able to create a model and automatically create a form using
> modelform
>
> My model contains a lot of table/class but I'm going to create the
> form only by means of on table/class
> this is part of the model:
>
> ______________________________________
>
> class TipoIndagine(models.Model):
>     cod_tipo = models.IntegerField(primary_key=True)
>     desc_tipo = models.CharField(max_length=100)
>     cod_classe = models.ForeignKey(ClasseIndagine,
> db_column='cod_classe')
>     class Meta:
>         db_table = u'tipo_indagine'
>
> class Indagine(models.Model):
>     cod_indagine = models.AutoField(primary_key=True)
>     #cod_indagine = models.IntegerField(IndaginiSpatial,
> db_column='cod_indagine')
>     cod_tipo = models.ForeignKey(TipoIndagine, db_column='cod_tipo')
>     data = models.DateField()
>     ditta = models.CharField(max_length=100)
>     cod_falda = models.ForeignKey(Falda, db_column='cod_falda')
>     cod_comune = models.ForeignKey(Comune, db_column='cod_comune')
>     localita = models.CharField(max_length=100)
>     quota_pc = models.DecimalField(max_digits=8, decimal_places=3)
>     usosuolo = models.CharField(max_length=100)
>     note = models.CharField(max_length=100)
>     cod_pratica = models.ForeignKey(Pratica, db_column='cod_pratica')
>     compilatore = models.CharField(max_length=100)
>     nome_indag = models.CharField(max_length=100)
>     the_geom = models.PointField()
>     objects = models.GeoManager()
>     def __unicode__(self):
>         return self.cod_tipo
>         #return u'%s' % self.cod_tipo
>     class Meta:
>         db_table = u'indagine'
> ___________________________________
>
> This is the simple form code:
> _______________________________
> class IndagineForm(ModelForm):
>     class Meta:
>         model = Indagine
> _______________________________
>
> The form is loading but the foreignkey fields only show a drop down
> list containing a lot of "nameOfClass object"
>
> I have read this 
> posthttp://groups.google.com/group/django-users/browse_thread/thread/02ad...
> And I put into the Indagine class these rows:
>     def __unicode__(self):
>         return self.cod_tipo
>
> but the __unicode__ method seems not to solve the problem.
>
> Now, using __unicode__ method as shown above, when I load my
> models.Indagine into the python shell and I call the class, I obtain:
>
> >>> from geotec_db.models import Indagine
> >>> Indagine.objects.all()
>
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py",
> line 69, in __repr__
>     return repr(data)
>   File "/usr/lib/python2.6/dist-packages/django/db/models/base.py",
> line 345, in __repr__
>     u = unicode(self)
>   File "/home/ivan/geotecdb_django/../geotecdb_django/geotec_db/
> models.py", line 92, in __unicode__
>     return u'%s' % self.cod_tipo
>   File "/usr/lib/python2.6/dist-packages/django/db/models/fields/
> related.py", line 264, in __get__
>     raise self.field.rel.to.DoesNotExist
> DoesNotExist
>
> I can't understand where is the problem...
>
> Please help me  :-)
>
> Ivan

That method should have gone in the TipoIndagine model.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to