I'm following the m2m_intermediary pattern:
9. Many-to-many relationships via an intermediary table
http://www.djangoproject.com/documentation/models/m2m_intermediary/
However, I need associations, not between two different models, but between
pairs of instances of the *same* model, as discussed in this thread:
Friendship_type on symmetrical M2M
http://groups.google.com/group/django-users/browse_thread/thread/72afc8b5540dd75e/68688173a04a027d
Take this Person model:
class Person(models.Model):
first_name = models.CharField(maxlength = 100)
last_name = models.CharField(maxlength = 100)
and associate pairs of persons, while adding some data:
class Association(models.Model):
person = models.ForeignKey(Person, related_name='friend_of')
associate = models.ForeignKey(Person, related_name='friends')
some_data = models.IntegerField()
The admin interface for these models works correctly.
Now, to be able to add Associations while editing Persons, I add
edit_inline and core to Association fields.
If I add them to both ForeignKey fields:
class Association(models.Model):
person = models.ForeignKey(Person, related_name='friend_of',
core=True, edit_inline=models.TABULAR)
associate = models.ForeignKey(Person, related_name='friends',
core=True, edit_inline=models.TABULAR)
dummy = models.IntegerField()
I get this error:
Traceback (most recent call last):
File ".../django/template/__init__.py" in render_node
754. result = node.render(context)
File ".../django/template/defaulttags.py" in render
134. nodelist.append(node.render(context))
File ".../django/contrib/admin/templatetags/admin_modify.py" in render
171. bound_related_object = relation.bind(
context['form'], original, bound_related_object_class)
File ".../django/db/models/related.py" in bind
129. return bound_related_object_class(self, field_mapping, original)
File ".../django/contrib/admin/templatetags/admin_modify.py" in __init__
138. for (i,field_mapping) in self.field_mappings.items() ]
File ".../django/oldforms/__init__.py" in items
264. self.fill()
File ".../django/oldforms/__init__.py" in fill
283. field = self.parent_manipulator[full_field_name]
File ".../django/oldforms/__init__.py" in __getitem__
28. raise KeyError, "Field %s not found\n%s" % (
field_name, repr(self.fields))
KeyError at /admin/person/add/
'Field association.0.associate not found
[FormField "first_name", FormField "last_name",
FormField "association.0.id", FormField "association.0.person",
FormField "association.0.dummy",
FormField "association.1.id", FormField "association.1.person",
FormField "association.1.dummy",
FormField "association.2.id", FormField "association.2.person",
FormField "association.2.dummy",
FormField "association.0.id", FormField "association.0.person",
FormField "association.0.dummy",
FormField "association.1.id", FormField "association.1.person",
FormField "association.1.dummy",
FormField "association.2.id", FormField "association.2.person",
FormField "association.2.dummy"]'
If I only add edit_inline and core to the first ForeignKey field:
class Association(models.Model):
person = models.ForeignKey(Person, related_name='friend_of',
core=True, edit_inline=models.TABULAR)
associate = models.ForeignKey(Person, related_name='friends')
dummy = models.IntegerField()
I get this other error:
Traceback (most recent call last):
File ".../django/template/__init__.py" in render_node
754. result = node.render(context)
File ".../django/template/defaulttags.py" in render
134. nodelist.append(node.render(context))
File ".../django/contrib/admin/templatetags/admin_modify.py" in render
171. bound_related_object = relation.bind(
context['form'], original, bound_related_object_class)
File ".../django/db/models/related.py" in bind
129. return bound_related_object_class(self, field_mapping, original)
TypeError at /admin/diet/person/add/
'bool' object is not callable
What am I missing?
--
Nicola Larosa - http://www.tekNico.net/
Django-developers isn't a "Help Desk Level 2"; please don't try to use
it as such. If it's been at least a week or so since your last try on
Django-users, you might try to re-raise the issue there.
Maybe too much politeness on my part obscured the main point, so let's be
blunt this time:
there's a bug in Django. (Oh, the horrors! ;-P ) Or maybe not, whatever.
Having followed all the steps in the bug reporting guidelines, I have
now filed ticket #4937:
http://code.djangoproject.com/ticket/4937
Do what you will with it, and thank you.
--
Nicola Larosa - http://www.tekNico.net/
The Christian religion, like those of Judaism, Islam and all the rest,
are manufactured belief systems to keep their advocates in mental and
emotional servitude, while being played off against each other
to divide and rule. -- David Icke, February 2007
actually, I find it a legitimate use of django-developers to report errors
that are probably caused by Django and look weird, especially if the mail
concentrates on the bug description and is, well, developer style (full
context etc.) It often helps to get to the point (or embarrass yourself ;-)
Is this widely accepted, or just me?
Michael
--
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk -
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689
Sorry about that; I've been on a hair-trigger lately regarding posters
misusing Django-developers, and I didn't immediately follow that you
were pointing out a possible bug in Django itself. I didn't mean to
catch you in the crossfire there. :-(
That's fine if you're fairly certain it's a bug in Django itself,
although I'd certainly avail myself of the bug tracker and reference
the ticket number so we can, well, track the issue. :-) My fault for
jumping on Nicola that way.
For future reference, you don't need to post to Django-developers to
tell us that you have logged a bug. The core developers and ticket
triage team keep a handle on the new tickets as they are submitted.
You should note that the bug reporting guidelines don't suggest you
should announce tickets on django-developers. You only need to start a
django-developers discussion if there is some sort of design issue to
resolve (for example, if you want to fix the bug, and want advice on
the correct solution to a problem).
Yours,
Russ Magee %-)
Russell Keith-Magee wrote:
> You should note that the bug reporting guidelines don't suggest you
> should announce tickets on django-developers.
Good to know. I'll now meta-break this rule to announce that I have made
the ticket #4942 with a patch to contributing.txt adding such rule. ;-)
> You only need to start a django-developers discussion if there is some
> sort of design issue to resolve (for example, if you want to fix the
> bug, and want advice on the correct solution to a problem).
Another thing I did not say clearly. Yes, I want to fix the bug. I'm going
to start a debugging session right now to try fixing it.
I understand it's probably related to oldforms, so I'd like advice about
which course of action to follow:
1) trying to fix the current code: how?
2) trying to use newforms-admin instead: how?
Marked as duplicate of #1939, sorry about that.
#1939 and lots of other tickets are listed at:
http://code.djangoproject.com/wiki/FeatureGrouping#edit_inlineIssues
It looks like newforms-admin is actually the way to go, I'll search the
wiki and this group for more info about it.
--
Nicola Larosa - http://www.tekNico.net/
Having a job is not unimportant, but if knowing Perl is a requirement
for a particular job, consider another one before taking that one.
This is true even if you know Perl very well. Life is too long to be
an expert at harmful things, including such evilness as C++ and Perl.
-- Erik Naggum on comp.lang.lisp, March 2000