I created a model playlist form and elements 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 also installed the login script. If you need to create a playlist, you need to log in, and the problem is that when I try to create a playlist after logging in, it displays all the users in the drop-down list with a list to select which user and enter the title of the playlist, What if I want to do to remove this useless dropdown. It also shows for the page element, for example, the selection of a playlist in the drop-down list and input of elements.
Thank.
source
share