the best schema for a django model with relation -


i have model user , model team. use fields of team , 1 field (username) of user not !

a team contains many users, these relation create model (1) :

class jointeam(models.model):     username_user=models.charfield(max_length=30)     team = models.foreignkey(projet, null=false) 

but hesitate replace field 'username_user' (2):

 class jointeam(models.model):     username_user=models.foreignkey(user, null=false)     team = models.foreignkey(projet, null=false)  i'm afraid model (2) consumes more capacity the first (1).  

how use simple charfield or foreignkey ?

i'm afraid model (2) consumes more capacity the first (1).

don't afraid, django store reference(pointer/id) user, not whole model instance.

you model should looks this:

class jointeam(models.model):     user=models.foreignkey(user, null=false)     team = models.foreignkey(projet, null=false) 

rename username_user user.

also, practice, trying not duplicate data, if store username in jointeam table, duplicating data, because, can obtain user table.


Comments