1๐
โ
Your view use StrategyHistory
model incorrect. That is the use of forms. This is correct.
def exercise_view(request, pk):
template_name = 'mobileApp/page/exercise.html'
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('mobile_user_login'))
strategy = Strategies.objects.get(pk=pk)
context = {
'strategy':strategy,
}
if request.method == 'POST':
strategyhistory = StrategyHistory.objects.create(
user=request.user,
strategy=strategy)
if pk < 5:
return HttpResponseRedirect(reverse('mobile_exercise', kwargs={'pk': pk + 1}))
else:
return HttpResponseRedirect(reverse('mobile_comeback_later'))
return render_to_response(template_name,
context,
context_instance = RC( request, {} ))
Also you cannot use self.request
in that view. There is no self declared.
0๐
May be this is what you want:
class StrategyHistory(models.Model):
user = models.ForeignKey(User)
strategy = models.ForeignKey(Strategies)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
def __unicode__(self):
return self.strategy.name
๐คshellbye
- [Answer]-Why when i logout in django after i updated my data appears this error?
- [Answer]-Django error on importing class from model
- [Answer]-Web text input save into database without form- Django Javascript
- [Answer]-How to avoid Cross-Origin Resource Sharing error when hitting a Django API from another server process?
Source:stackexchange.com