Should I change my UserProfile table or create other tables to hold additiaonl user info after user login

StackOverflow https://stackoverflow.com/questions/17441115

  •  02-06-2022
  •  | 
  •  

Domanda

In my project, after login, the user have to go through a few process to input their personal particulars, upload some files

Now I have finished the auth process

there are only three fileds in my UserProfile

models.py

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    #activation_key is used in my account registration process
    activation_key = models.CharField(max_length=40) 
    #activation link should be only valid for one day       
    key_expires = models.DateTimeField() 


    def __unicode__(self):
       return self.user.username

these three fileds are enough to make the auth process works properly.

Initially in my DB design, I use other tables to hold the personal particulars and the files(as I was not ware yet that I am supposed to use the UserProfile to hold additional data for the user). But after going through the auth process and coming across many posts in the stackoverflow, it seems that I should put the data in the UserProfile table.

So my question is,

  1. Can UserProfile contain data both for the auth process(e.g. activation_key key_expire_date) and the specific data e.g. name, country, picture ? (now my UserProfile contains only the data for the auth process)

  2. In this situation, adding new fields now or create anther table to hold the additional info, which one is the better practice for a Django project?

  3. If I add new fields to the UserProfile, would it affect my previous auth functions?(I am a bit concerned about the profile.save() issue..)

Thank you very much for clarifying.

È stato utile?

Soluzione

There should be no issue in adding further fields to your UserProfile object - as long as you don't change the data in the columns used by the auth process then you will be fine.

With regards to whether you should split the users 'auth' data from their other data (name, country etc) is really a design question. If you expect that every users profile will always have both kinds of data, then having them together in one table probably makes sense. However, if a user may have 'auth' data, but not necessarily have the other data at any given time, then it probably makes sense to split them into two tables so that the data sets can be maintained separately.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top