On 4/04/2013 5:15pm, Russell Keith-Magee wrote:

On Thu, Apr 4, 2013 at 1:01 PM, Mike Dewhirst <mi...@dewhirst.com.au
<mailto:mi...@dewhirst.com.au>> wrote:

    I have noticed that there appears to be no difference in Postgres
    between a OneToOneField and a ForeignKey with unique=True

    Is there any/much difference in Django?

At a database level - no. The implementation is identical, to the extent
that OneToOneField is a subclass of ForeignKey that forces unique=True.

At an API level, there is one very small difference. The default reverse
accessor for a Foreign Key will be named '<object name>_set', and it
will return a QuerySet. The default reverse accessor for a OneToOne Key
will be named '<object name>', and it will return a single object.

Thank you. Makes good sense. It is nice to have that flexibility for my own API. And obviously I can change my mind and rework the code without touching the database.

Much appreciated.

Mike



Yours,
Russ Magee %-)

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to