How to design content share model for social network in Django? -


this not program bug fix problem. looks silly, since don't have experience in designing website. want make sure design pattern right before began write code.

i want design social network google+ or facebook(only accomplish basic function sharing content), google+, users can share different types of content texts, photos, link , video. picture below: enter image description here

i'm confused need design different model every type sharing content? below codes:

class textpost(models.models):     text=models.charfield(max_length=140)     createdate=models.datetimefield(auto_now_add=true)     author=models.onetoonefield(user)  class gallerypost(models.model):     gallerytitle=models.charfield(max_length=140)     createdate=models.datetimefield(auto_now_add=true)       author=models.onetoonefield(user)  class images(models.models):     image = models.imagefield()     gallerypost=models.foreignkey(gallerypost)  class linkpost(models.models):     link=...     createdate=...  class videopost(models.models):     video=... 

or put types in 1 class:

class post(models.model):     text=models.charfield(max_length=140)     createdate=models.datetimefield(auto_now_add=true)     author=models.onetoonefield(user)     gallerytitle=models.charfield(max_length=140)     link=...     video=... 

if choose first way, easy list kinds of post created date in 1 page? or there other better way?

while both approaches valid approaches, first 1 difficult query against. want show mixed feed of latest content, preferably easy query database against.

in case want models have base class, defines shared attributes (author, created_at). specific sub-classes, add desired attributes. see model inheritance on docs.djangoproject.com.

class post(models.model):     author = models.foreignkey('auth.user')     created_at = models.datetimefield()  class linkpost(post):     link = models.urlfield()  class imagepost(post):     image = models.imagefield() 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -