On Sun, 2009-08-02 at 14:08 -0700, Unnamed_Hero wrote:
> I have a table with a list of corporations; each corp has a field with
> it unique number.
> There is a table, filled with people, each record contains a field
> with a corp's unique field (where each person works)
> 
> Task: when displaying info about corporation, also fetch info about
> people working at.
> 
> Also there are several tables with such relationship with a corp
> table.
> 
> So, it seems to be a many-to-many relationship.
> 
> there is come code
> 
> class c12b (models.Model):
>     id = models.AutoField (primary_key=True)
>     A15 = models.CharField ('Телетайп', max_length=20,  blank= True)
>     A17 = models.CharField ('Телекс', max_length=20,  blank= True)
>     A19 = models.CharField ('Факс', max_length=40,  blank= True)
>     A34  = models.CharField ('Код промышленности',max_length=5,
> blank=True)
>     A29 = models.CharField ('E-mail', max_length=50, blank=True)
>     A30 = models.CharField ('Сайт', max_length=40,  blank= True)
>     A3 = models.CharField ( 'ИНН',max_length=10, blank=True)
>     A21  = models.CharField ('Реквизиты банка' ,max_length=255,
> blank=True)
>     A22 = models.CharField ('Код ОКПО', max_length=8, blank=True )
> #CORP INIQUE KEY
> #here I've tried to create a related field
>     boss = models.ManyToManyField (Dolgnost, db_column="A22",
> through='bosses_table')
>     class Meta:
>         db_table='C12B'
> 
> class bosses_table (models.Model):
>     c12b = models.ForeignKey (c12b,  to_field="A22")

I'm surprised Django didn't raise a validation error here, since
c12b.A22 is required to be a unique field in order to be the target of a
to_field parameter and you haven't marked it as unique in the above
model.

>     dolgnost = models.ForeignKey (Dolgnost,
> to_field="A22",unique=False)
> 
> 
> #in view.py
> ...
> result = c12b.objects.filter(A34__exact ="02100")
> return render_to_response ("prkp/lista.html",  {
>                                                    "result":result,
> ...
> #template
> {% for i in result %}
>     <tr>
>     {% for b in i.boss.all %}
>     {{ b.U1 }}
>     {% endfor %}
>     <td>{{ i.boss.U1 }}</td>
> 
> Finally I've got an exeption
> Caught an exception while rendering:relation "search_bosses_table"
> doesn't exist

I would start by removing as many variables from the debugging situation
as possible. In particular, instead of debugging this through the
template system, use an interactive shell. Work out the exist record in
"result" that is causing the problem so that you can narrow things down
to the exact piece(s) of data that are causing the problem.

There doesn't seem to be anything immediately wrong with your models,
although I would put some effort into naming the fields more
descriptively ("A34" is hardly easy to debug when it pops up in a
traceback). I would also simply make A22 the primary key of the c12b
model (and probably the boss model as well, if it's similar) so that you
don't even need the intermediate table and can just use a normal
ManyToManyField. Generally, if you are using "through" on a
ManyToManyField, it would be because the intermediate table contains
more than just the two linking fields.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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