Integrate Django Models with a User Account
Does anyone have a list of things they do to associate some model with a user?
I.e. if a blog entry has a user, you have to do a fe开发者_运维百科w things: - Add a foriegnkey field - Make the foreign key field editable = False - On save/load make sure that request.user matches entry.user
This is what I could come up with. Is there an easier way to do this? Anything else to keep in mind?
It may make more sense to associate the model with a user Profile object than to associate directly with User. That way it's easier to connect the model to custom attributes of the user.
That is an appropriate way, although it may be useful to have it editable. The user should be assigned in the view, not pushed through to the model, in order to maintain clean MVP separation.
精彩评论