Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:06:27+00:00 2026-06-14T14:06:27+00:00

I am trying to create functionality that allows a user to save items to

  • 0

I am trying to create functionality that allows a user to save items to a playlist and the user can have multiple playlists. Each item can be saved to multiple playlists as well. What is the best way to represent this data? Multiple tables with foreignkeys linking them or just 1 flat table?

multiple tables

class Playlist(models.Model):
    playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
    def __unicode__(self):
        return self.playlist
    
class Video(models.Model):
    video_url = models.URLField('Link to video', max_length = 200, null=True, blank=True)
    video_tag = models.CharField('Video ID', max_length = 2000, null=True, blank=True)
    def __unicode__(self):
        return self.video_url

class UserPlaylist(models.Model):
    profile = models.ForeignKey(User)
    playlist = models.ForeignKey(Playlist)
    def __unicode__(self):
        return unicode(self.playlist)

class Videoplaylist(models.Model):
    video = models.ForeignKey(Video)
    playlist = models.ForeignKey(UserPlaylist)
    def __unicode__(self):
        return unicode(self.playlist)

1 table

class Everything(models.Model):
    profile = models.ForeignKey(User)
    playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
    platform = models.CharField('Platform', max_length = 2000, null=True, blank=True)
    video = models.CharField('VideoID', max_length = 2000, null=True, blank=True)
    def __unicode__(self):
        return u'%s %s %s %s' % (self.profile, self.playlist, self.platform, self.video)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:06:28+00:00Added an answer on June 14, 2026 at 2:06 pm

    There are two main relationships between the entities:

    • Playlist –> User, many to one
    • Video –> PlayList, many to many

    Based on the above, you should arrange your data in a way like this:

    class User():
        name = CharField()
        # other user info
    
    class Video():
        name = CharField()
        # othter video info
    
    class Playlist():
        user = ForeigenKey(User)
        name = CharField()
    
    class PlaylistVideo():
        plist = ForeigenKey(Playlist)
        video = ForeigenKey(Video)
    
    # When a user adds a video to one of his playlist
    def add_video_to_playlist(user_name, playlist_name, video_name)
        user = User.objects.get(name=user_name)
        plist = Playlist.objects.get(user=user, name=playlist_name)
    
        video = Video.objects.get(name=video_name)
        plv = PlaylistVideo(plist=plist,video=video)
        plv.save()
    
    # To get the content of a user's some playlist:
    def get_playlist_content(user_name, playlist_names):
        user = User.objects.get(name=user_name)
        plist = Playlist.objects.get(user=user, name=playlist_name)
    
        return [plv.video for plv in PlaylistVideo.objects.filter(plist=plist)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a 'tag' functionality which allows a user to tag items
I am trying to create an application that allows the user to search a
I'm trying to create some functionality that allows me to arbitrarily show a collection
What I am trying to do is create tooltip functionality so that certain words
Background: I'm trying to create a pure D language implementation of functionality that's roughly
I'm trying to develop a ff addon that allows a user to right-click on
I am trying to get the same functionality that a combobox has, like combobox1.Items.Add()
I'm trying to create some functionality that keeps an audit trail of how data
I am trying re-create the facebook tagging functionality, where you click on an image
I am trying to create the subroutine mypush with similar functionality of inbuilt push

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.