django - Store user specific data for each object -


if have eg app stores articles , each of these articles can rated user. rating not visible other users , user specific (no overall rating) ie each rating of same article-object needs stored each user.

currently complete crazy stuff:

class article(models.model):         text = models.textfield(null=true, blank=true)      def __unicode__(self):         return self.text   class userarticlestorage(models.model):     user = models.onetoonefield(settings.auth_user_model,                                 on_delete=models.cascade,                                 null=true,                                 )      articles_rated_1 = models.manytomanyfield(         article,         related_name="articles_rated_1",         blank=true     )     articles_rated_2 = models.manytomanyfield(         article,         related_name="articles_rated_3",         blank=true     )     articles_rated_3 = models.manytomanyfield(         article,         related_name="articles_rated_3",         blank=true     ) 

and them in view e.g. request.user.userarticlestorage.articles_rated_3

what normal way store user specific rating integerfield?

i think can defining simple model:

class rating(models.model):     article = models.foreignkey(article, ..., related_name='ratings')     user = models.foreignkey(settings.auth_user_model,, ..., related_name='ratings')     rate = models.integerfield() 

and access ratings by:

request.user.ratings 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -