Is there a reason why you're storing an email address instead of just selecting the user or creating a new one?
On Oct 10, 12:41 am, Andrew Pendleton <abp...@gmail.com> wrote: > I'm trying to figure out the best way to add an email address form > field to the edit page for a model in the Django admin, and, upon > save, automatically set a hidden foreign key to associate said model > instance to the Django user with this email address, or, > alternatively, create a new user with said email address if one > doesn't already exist. > > Things I've thought of: > * Add an actual database field for the email address, in addition to > the ForeignKey that's already there, and add some glue in the save() > method to set the second based on the first. This seems to be the > easiest to implement, but I don't like the unnecessary duplication of > data, and I'd also like the foreign key relationship to be maintained > once it's set, even if the email address of the User changes, and it > seems like there's risk of breakage in that event, with this approach. > * Use a custom form for the model in the admin that tacks on an extra > field, and, again, do some voodoo in save. > * Make the foreign key field visible, but write a custom widget for it > that looks like a regular text box, but looks to Django like a foreign > key field. > > Would any of these work well? If so, which would be best? Am I > missing anything? With which might it be easiest to reuse the same > logic in a piston-powered API that exhibits the same behavior? > > Relatedly, in my application, it will be possible, but rare (and > likely unintentional) for more than one instance of this model to be > associated with the same User instance. In the event that I get this > kind of likely-incorrect submission, is there a way to force a > confirmation screen with a warning on it for a save in the admin, but > let the user proceed if they really want to? > > Thanks, > Andrew --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---