その質問はカバーされていると確信していますが、問題を解決するためにスタックに関連するものをすべて試しましたが、成功しませんでした。
これが私のmodel.pyです
from django.db import models
from django.contrib.auth.models import User
class Description(models.Model):
titre_routine = models.CharField(max_length=100)
type_routine = models.CharField(max_length=100)
lieu_routine = models.CharField(max_length=100)
periode = models.CharField(max_length=100, blank=True)
routine_description = models.TextField()
raison_chgmt = models.TextField(blank=True)
user = models.ForeignKey(User)
#prendre une liste de routine et faire une liste de choix
#si non ajout a la liste de routine dans nouvelle table
def __unicode__(self):
return self.titre_routine
#User.profile = property(lambda u: Description.objects.get_or_create(user=u)[0])
class Rewards(models.Model):
jour = models.CharField(max_length=4)
activite_altr = models.TextField()
first_word = models.CharField(max_length=100, blank=True)
second_word = models.CharField(max_length=100, blank=True)
third_word = models.CharField(max_length=100, blank=True)
urge_validator = models.BooleanField() #urge satisfait ou non?
urge_validate_date = models.DateField(auto_now=True)
description = models.ForeignKey(Description)
def __unicode__(self):
return self.jour
私のモデルを説明するには: 1 人の「ユーザー」が複数の「説明」を作成できます。「説明」には複数の「報酬」が含まれています。...「説明」には複数の「その他のもの」が含まれます
ここに私のview.pyがあります
#the user access to his dashboard, dashboard filtered by the user logged in.
@login_required(login_url='/userauth/login/')
def dashboard(request):
routine_info = Description.objects.filter(user=request.user)
return render_to_response('dashboard.html', {
'routine_info': routine_info
})
#dashboard for the reward section that should be like the first dashboard filtered only by the user logged in AND should only show the reward related to One description created previously by the user.
@login_required(login_url='/userauth/login/')
def reward_dashboard(request):
reward_info = Rewards.objects.all()
return render_to_response('rewards_dashboard.html', {
'reward_info': reward_info
})
#the user can have access to the reward he created as the other def, he should be the only one to have access (again reward created by the user and related to ONE description)
@login_required(login_url='/userauth/login/')
def reward_description(request, reward_id):
reward_info = Rewards.objects.get(id=reward_id)
return render_to_response('reward_description.html', {
'reward': reward_info
})
#rewardform, I miss the pieces to obtain de description id that will link both table Rewards and Description (and recursively the User table via Description???)
@login_required(login_url='/userauth/login/')
def new_reward(request):
if request.POST:
form = RewardsForm(request.POST)
if form.is_valid():
obj = form.save(commit= False)
obj.description = #Missing piece
#test that could never happen
if obj.description == 200:
return HttpResponseRedirect('/reward_dashboard/')
else:
obj.save()
return HttpResponseRedirect('/reward_dashboard/')
else:
form = RewardsForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_reward.html', args)
要約すると:
-ユーザーは、自分が作成した報酬にアクセスできます。他の定義として、アクセスできるのは彼だけである必要があります (ここでも、ユーザーによって作成され、1 つの説明に関連する報酬)
-報酬セクションのダッシュボードには、最初のダッシュボードがログインしているユーザーによってのみフィルタリングされ、以前に作成された報酬関連の One の説明のみが表示される必要があります。
-報酬フォーム、テーブル報酬と説明の両方をリンクする説明IDを取得するためのピースがありません(および説明を介してユーザーテーブルを再帰的にリンクします)
セッションを調べてみるべきですか?(ユーザーが説明を作成するとき、私は彼に特定の ID を割り当てますか?)
私の説明で私の主張が明確になったことを願っています。
お手伝いありがとうございます!