Reputation: 35
How can i use in my views instances from other class?
For example in my views i have:
MODELS
class Projekt(models.Model):
nazwa_projektu = models.CharField(max_length=200, unique=True)
opis_projektu = models.TextField()
wybor_projekt = models.CharField(max_length=100, choices=wybor_t_f, default="FALSZ")
VIEWS
def ProjektViewOptions(request, pk):
profil = Profil.objects.get(user=request.user)
projekt = Projekt.objects.get(id=pk)
srodek = projekt.srodek_set.all
form = OptionsForm(request.POST or None)
template_name = 'viewOptionsProjekt.html'
if request.method == "POST":
if form.is_valid():
pro.wybor_projekt = 'PRAWDA'
pro.save()
opcje = form.save(commit=False)
opcje.wlasciciel = profil
opcje.projekt = projekt
opcje.save()
opcje.wybor = 'PRAWDA'
form.save()
I want to do that, if i create a new Project this project have a options "FALSZ" when I "POST" this options will turn into the "PRAWDA"
I tried do :
opcje.projekt.wybor_projekt = "PRAWDA"
But this unfortunately dont work.
I dont want full solution. I need a little direction. ;)
Upvotes: 0
Views: 258