Hi folks,
I don't like replying to my own mails, but I'm working against a
deadline here. Is it possible to do what I want? Luke wrote:
> limit_choices_to is (essentially) a class level attribute, and has
> no access to instance level data.
which probably means that I can't do what I want based on the
limit_choices_to attribute. What I need is something that can join and
select based on instance level data, but preferably be able to define
it at the class level.
Greetings,
Sybren
On Tue, Aug 22, 2006 at 12:20:10PM +0200, Sybren Stüvel wrote:
>
> 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/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---