I've created modelform of playlist and items like this:
class playlistmodel(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=200)
def __unicode__(self):
return self.title
class itemsmodel(models.Model):
playlist = models.ForeignKey(playlistmodel)
item = models.TextField()
def __unicode(self):
return self.item
class playlistform(ModelForm):
class Meta:
model = playlistmodel
class itemsform(ModelForm):
class Meta:
model = itemsmodel
My playlist view:
def playlistview(request):
if request.method == 'POST':
form = playlistform(request.POST)
if form.is_valid():
data = form.save(commit=False)
data.user = request.user
a = data.save()
return render_to_response('playlist.html', {'data': a})
else:
form = playlistform()
playlistmodel.user.id = request.user.id
return render_to_response('playlist.html', {'form': form}, context_instance=RequestContext(request))
I've also set up with login script. If you need to create a playlist, you need to login and the problem is when I'm trying to create a playlist after logging in, it shows all the users in the dropdown combo box to select which user and enter the title of the playlist. What if I want to do to remove that useless dropdown box. It also shows for item page like selecting the playlist in the dropdown box and entering the items.
Thank you.