Wednesday, November 30, 2011

Delete a many to many field who is in another table

Hi, I am finally going to finish the project started and where I end
up liking this xD Django that the problem I have is the clearing of a
field.
I have the following tables.

class Proyectos(models.Model):
titulo=models.CharField(max_length=100)
creacion=models.DateField(default=datetime.datetime.now)
estado=models.CharField(max_length=30)
objetivo=models.TextField(null=True)
conclusion=models.TextField(null=True)
porcentaje=models.IntegerField()
modificado=models.DateTimeField(default=datetime.datetime.now)
autor=models.IntegerField()
usuarios=models.ManyToManyField(User)
proyectos_rel=models.ManyToManyField("self")
documentos=models.ManyToManyField(Documentos)
class Meta:
db_table='Proyectos'
def __unicode__(self):
return self.titulo

class Experimentos(models.Model):
titulo=models.CharField(max_length=100)
creacion=models.DateField(default=datetime.datetime.now)
estado=models.CharField(max_length=30)
objetivo=models.TextField(null=True)
conclusion=models.TextField(null=True)
porcentaje=models.IntegerField()
modificado=models.DateTimeField(default=datetime.datetime.now)
autor=models.IntegerField()
proyecto=models.ForeignKey(Proyectos)
usuarios=models.ManyToManyField(User)
experimentos=models.ManyToManyField("self")
documentos=models.ManyToManyField(Documentos)
class Meta:
db_table='Experimentos'
.
I want to eliminate only one of the experiments which may contain a
Project
I try like this:

if request.POST.get('experimentosDelete','')!='':
for i in request.POST.getlist('experimentosDelete'):
exp=Experimentos.objects.get(proyecto=datos,id=i)
exp.experimentos.remove(request.POST.get('experimentosDelete'))

The result is that it does nothing ....... and otherwise remove whole
objects, not the relationship.I don't know .
I greatly appreciate your help in all questions.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment