Sunday, August 29, 2010

Model validation for non-django-orm databases

I've got an external (read-only) database that I'd like to hook into
an app I'm working on -- it violates django's pk assumption by using
composite keys.

I'm hoping that, given a couple of assumptions of my own, I can hook
these tables up to the ORM without having the universe implode.
Since the database is read-only, I don't need (or want) the content to
be accessible via the admin site.
Queries against the tables with composite keys will never (in my own
code) make reference to pk, I'll always be using N values for the
fields that make up the composite key.

I've read that a "hack" around this kind of issue is to use the meta
unique_together property and almost arbitrarily set primary_key on one
of the fields. That sounds great, except for the fact that I've got
no guarantee that any given field will actually be unique -- which
column do I add the primary_key to? Basically, since the content is
being generated externally, and integrity is being managed on that
end, do I need to worry about this?

As long as the model loads/validates I'm happy. Is there anything I
need to look out for here?

Best regards,
Owen Nelson

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment