I use modelforms to get the playlist and its elements. It also contains a login script. I am trying to set the current user to a user model. You can see this thing that I posted earlier.
How to avoid this combobox?
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
exclude = {'user'}
class itemsform(ModelForm):
class Meta:
model = itemsmodel
exclude = {'playlist'}
Here is the 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
data.save()
return render_to_response('playlist.html', {'data': data})
else:
form = playlistform()
return render_to_response('playlist.html', {'form': form, 'user': request.user}, context_instance=RequestContext(request))
Playlist.html file:
https://gist.github.com/1576136
Error page:
https://gist.github.com/1576186
But I get ValueError:
Exception Type: ValueError Exception Value: Cannot assign "<django.utils.functional.SimpleLazyObject object at 0x7f0234028f50>": "playlistmodel.user" must be a "User" instance
Traceback: Local vars --- data.user = request.user
Here are my settings .py
https://gist.github.com/1575856
Thank.
source
share