django - Storing data in different tables or using bool fields -
i have article
table
class article(models.model): """ model keep articles """ ext_id = models.uuidfield(primary_key=true, db_index=true, default=uuid.uuid4, editable=false) title = models.charfield(max_length=255, unique=true, db_index=true) content = models.textfield() summary = models.textfield() img_url = models.urlfield(max_length=200) author = models.charfield(max_length=50, blank=true, null=true) sport = models.foreignkey('sport') posted_on= models.datetimefield() created = models.datetimefield(auto_now_add=true) updated = models.datetimefield(auto_now=true) def __unicode__(self): return "%s %s" % (self.title, self.author)
a table store articles liked user :
class likedarticle(models.model): """ articles user wants read """ ext_id = models.uuidfield(primary_key=true, default=uuid.uuid4, editable=false) article = models.foreignkey(article) profile = models.foreignkey(profile) created = models.datetimefield(auto_now_add=true) updated = models.datetimefield(auto_now=true)
and unliked :
class unlikedlikedarticle(models.model): """ articles user not want read """ ext_id = models.uuidfield(primary_key=true, default=uuid.uuid4, editable=false) article = models.foreignkey(article) profile = models.foreignkey(profile) created = models.datetimefield(auto_now_add=true) updated = models.datetimefield(auto_now=true)
now here, both tables liked , unliked, structurally same. find better store instead of storing bool field called is_liked
because know data storing. don't have query huge set of articles when know interested in likedarticle
. correct approach ? confused because structurally same , doesn't feel right design.
the best approach recommend use 1 table , add is_liked
field. (and add index field, high performance queries)
but if still want use approach 2 table, need fix design.
use 1 abstract model has fields, , , unlike tables inherit abstract model
class actiononarticle(model): fields here.. class meta: abstract = true class likedarticle(actiononarticle): class unlikedarticle(actiononarticle):
Comments
Post a Comment