Friday, October 20, 2017

RE: How to store a key to a something that can be either a person or an organization?

In my project, I have a contacts model.

I have separate models, such as Person, Institution, Supplier, or Shipper that all have a foreign key to contacts.

So it looks like you're doing it the way that I would do it.

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Jani Tiainen
Sent: Friday, October 20, 2017 2:24 PM
To: django-users@googlegroups.com
Subject: Re: How to store a key to a something that can be either a person or an organization?

 

I would be a bit cautious with generic foreignkeys since they don't provide database integrity checks.

 

IOW, you can break your data very easily.

 

On 20 Oct 2017, at 19.55, Ruben Alves <rubenalvesbcn@gmail.com> wrote:

 

You can use Generic Key: https://docs.djangoproject.com/en/1.11/ref/contrib/contenttypes/

 

 


Em sexta-feira, 20 de outubro de 2017 07:59:35 UTC-2, Antonis Christofides escreveu:

Hello, 

Two real examples that I've faced: 

    class MeteorologicalStation(models.Model): 
        ... 
        owner = models.ForeignKey(to a person or organization) 


    class Document(models.Model): 
        ... 
        authors = models.ManyToManyKey(to persons or organizations) 

What I do is I create a superclass that I call Lentity (short for "legal 
entity", despite the fact that it could refer to a group of people and is not 
necessary legal) and the two subclasses Person and Organization, with 
multi-table inheritance. 

But since I guess that this is a relatively common problem, I was wondering 
about what other people are doing. 

Thanks! 

Antonis 

-- 
Antonis Christofides 
http://djangodeployment.com 

 

-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 
django-users+unsubscribe@googlegroups.com.
To post to this group, send email to 
django-users@googlegroups.com.
Visit this group at 
https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f1fcc861-b3f3-43dc-9bad-a2511de4da44%40googlegroups.com.
For more options, visit 
https://groups.google.com/d/optout.

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/72D4C974-6300-4F06-8C80-C4E0EA9D398F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment