hi
I have following problem.
I have model:
class Towar(models.Model):
nrSeryjny=models.CharField(max_length=100)
opis=models.CharField(max_length=255)
naStanie=models.NullBooleanField(null=True)
def __unicode__(self):
return "%s" % self.opis
def lowerName(self):
return self.__class__.__name__.lower()
def checkState(self):
return self.naStanie
def changeState(self,state):
self.naStanie=state
class Meta:
ordering=['nrSeryjny']
app_label = 'baza'
permissions=(("view_towar","mozna miec podglad dla towar"),)
and model :
class Wypozyczenie(models.Model):
dataPobrania=models.DateField()
pracownik=models.ForeignKey(User,null=True)
kontrahent=models.ForeignKey(Kontrahenci,null=True)
towar=models.ForeignKey(Towar,null=True)
objects=WypozyczenieManager()
default_objects=models.Manager()
ZwrotyObjects=WypozyczenieZwrotyManager()
def lowerName(self):
return self.__class__.__name__.lower()
def __unicode__(self):
if self.towar == None:
return "Dla:%s -- Kto:%s -- Kiedy:%s -- Co:%s" % (self.kontrahent,self.pracownik,self.dataPobrania,"Brak")
else:
return "Dla:%s -- Kto:%s -- Kiedy:%s -- Co:%s" % (self.kontrahent,self.pracownik,self.dataPobrania,self.towar)
class Meta:
ordering=['dataPobrania']
app_label = 'baza'
permissions=(("view_wypozyczenie","mozna miec podglad dla wypozyczenie"),)
and view to adding models:
def modelAdd(request,model,modelForm):
mod=model()
if request.user.has_perm('baza.add_%s' % mod.lowerName()):
if request.method=='POST':
form=modelForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/'+ mod.lowerName() + '/')
else:
form=modelForm()
v=RequestContext(request,{'form':form})
return render_to_response('add_form.html',v)
and i whant do that, when i add Wypozyczenie and save it then the Towar that is stored by Wypozyczenie change his na stanie from True to False
Greets