Today i was looking at this. I'll just drop my attempt at the
definition API:

class Entity:
    account = models.CharField()
    number = models.IntegerField()

    class Meta:
        primary_key=('account', 'number')

class Invoice:
    number = models.IntegerField()
    group = models.CharField()
    year = models.CharField()

    entity = models.ForeignKey(Entity)
    # will create entity_account and entity_number attributes

    class Meta:
        primary_key=('number', 'group', 'year')

class InvoiceItem:
    invoice = models.ForeignKey(Invoice)
    number = models.IntegerField()

    product = models.ForeignKey('...')

    class Meta:
        primary_key=('invoice', 'number')
        # OR
        primary_key=('invoice__number', 'invoice__group',
'invoice__year', 'number')

On Nov 13, 6:53 pm, David Cramer <[EMAIL PROTECTED]> wrote:
> Here's my proposal for the composite keys (which act much like generic
> keys except more useful):
>
> class MyModel2:
>     pass
>
> class MyModel3:
>     pk_part1 = models.AutoField()
>     pk_part2 = models.ForeignKey(MyModel2)
>     name = models.TextField()
>
> class MyModel:
>     pk_part1 = models.IntegerField()
>     pk_part2 = models.ForeignKey(MyModel2)
>
>     mymodel3 = models.CompositeForeignKey(MyModel3, pk_part1=pk_part1,
> pk_part2=pk_part2)
>
> MyModel.objects.filter(mymodel3__name="Hi")
>
> Anyways, I think you get the gist. I think this would cover all use
> cases, and is a very simple, similar, and clean API.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to