On Mon, Aug 21, 2006 at 01:18:03PM -0400, Waylan Limberg wrote: > In either case, you may want to take a look at the limit_choices_to > argument of many-to-one fields[1].
Could you give me an example of how to do this? I've tried the
following. The source is in Dutch, but I'd rather copy & paste than
translate, so that I'm sure there are no mistakes in that area.
"Levensverzekering" is "LifeInsurance", "KlantProfielData" is
"CustomerData" and "Hypotheek" is "Mortgage".
class Levensverzekering(models.Model):
class Admin:
pass
klantprofiel = models.ForeignKey(KlantProfielData,
related_name='levensverzekeringen',
edit_inline=models.STACKED, num_extra_on_change=1,
num_in_admin=1)
ing = DateField(core=True, help_text='Ingangsdatum')
eind = DateField(core=True, help_text='Einddatum')
koop = PositiveIntegerField(core=True, help_text='Koopsom')
pre = PositiveIntegerField(core=True, help_text='Premie')
hyp = models.ForeignKey(
Hypotheek,
core=True,
blank=True,
limit_choices_to={'klantprofiel__exact': klantprofiel}
)
But this gives me the following error:
ProgrammingError at /django/admin/profiel/levensverzekering/add/
ERROR: syntax error at or near "<" at character 364 SELECT
"profiel_hypotheek"."id", "profiel_hypotheek"."klantprofiel_id",
"profiel_hypotheek"."aanvang", "profiel_hypotheek"."looptijd",
"profiel_hypotheek"."instelling", "profiel_hypotheek"."vorm",
"profiel_hypotheek"."hoofdsom", "profiel_hypotheek"."hypotheekrente",
"profiel_hypotheek"."rentevast" FROM "profiel_hypotheek" WHERE
("profiel_hypotheek"."klantprofiel_id" =
<django.db.models.fields.related.ForeignKey object at 0xb6f3850c>) ORDER BY
"profiel_hypotheek"."aanvang" ASC, "profiel_hypotheek"."looptijd" ASC
This:
"profiel_hypotheek"."klantprofiel_id" =
<django.db.models.fields.related.ForeignKey object at 0xb6f3850c>
of course isn't proper SQL. Another thing I tried was nearly the same
code, except another limit_choces_to clause:
limit_choices_to={'klantprofiel__exact': klantprofiel.id}
Which gives me an error on the development server terminal:
kp.profiel: 'ForeignKey' object has no attribute 'id'
I've also tried this:
limit_choices_to={'klantprofiel_id__exact': klantprofiel}
Which gives me:
Cannot resolve keyword 'klantprofiel_id' into field
I don't know what else to try. Thanks in advance for any help or
suggestions.
Greetings,
--
Sybren Stüvel, B.Sc.
Stüvel IT
http://www.stuvel.eu/
signature.asc
Description: Digital signature

