On Mar 8, 3:01 pm, Derek <gamesb...@gmail.com> wrote:
> I am working with a legacy database and would appreciate some advice.
>
> I have an existing "user" table, with some fields that overlap with the
> design of Django's "user" table, and some fields that are "extra" to it.  I
> understand that I can use Django's "user" table and extend it to include
> these extra fields.
>
> However, the problem lies with the user's "id" field.  In the legacy
> database, this id appears in numerous tables (to identify the person who
> last edited the record) but is a short character string, NOT an
> auto-increment numeric value.  I am wondering what is the best/possible
> approach in order to use all the features of Django admin without any code
> changes.  I assume I will need to convert all the existing users into the
> Django user table, but then do I:
>
> a. leave the id field in the other tables "as is"?  In which case, is it
> possible to somehow adapt Django's numeric id field to become alpha-numeric?
>
> b. carry-out a mass update and convert all existing user id's in all tables
> to the Django numeric format?
>
> I think (b) might be better in the long run (although I am partial to the
> idea of "human readable" id string when browsing the raw data), but I would
> welcome other opinions (or options).
>
> Thanks
> Derek

A Django ForeignKey field doesn't have to point at the related table's
id column - you can use the 'to_field' attribute of the ForeignKey to
point it at a different field. So I would suggest keeping your non-
numeric key as (eg) 'legacy_key', and in your related models use:
     user = ForeignKey(UserProfile, to_field='legacy_key').

Would that work?
--
DR.

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

Reply via email to