Monday, April 8, 2019

Re: Update many to many django

Hola Luis, eres muy amable en responderme tan rápido, mi pregunta puntual es de que manera puedo hacer un update en una tabla de muchos a muchos.


Estos son mis dos modelos


class Articulo(models.Model):
    titulo = models.CharField(max_length=255, blank=True)
    texto = models.TextField()
    url = models.CharField(max_length=255)
    fuente = models.ForeignKey(Fuente, on_delete=models.CASCADE) #
    fecha = models.DateTimeField(null=True)
    created_at = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name=u'Fecha de creación')
    ubicacion = models.CharField(max_length=255)
    tipo_facebook = models.CharField(max_length=255)
    id_articulo_facebook = models.CharField(max_length=255,blank=True, null=True)

----------------------------


class Articulo_Consolidacion(models.Model):
    articulo =  models.ForeignKey(Articulo, on_delete=models.CASCADE)
    tag = models.ForeignKey(Tag, on_delete=models.CASCADE)
    tono = models.ForeignKey(Tono, on_delete=models.CASCADE)
    tema = models.ForeignKey(Tema, on_delete=models.CASCADE)

quedo muy atenta a tu respuesta.

Muchas gracias


El lun., 8 de abr. de 2019 a la(s) 21:11, Luis Zárate (luisza14@gmail.com) escribió:
Hola,

Las relaciones M2M pueden trabajarse de diferentes formas, acá está la doc de django

Si lo que quieres es hacer algo rápido puedes usar un model form factory

del  modelo que desear y luego relacionarlo con el objeto que quieras por ejemplo

Si lo único que necesita es relacionarlos porque los tiene ya creados entonces puede hacer  un formulario y usar un campo como ModelMultipleChoiceField (https://docs.djangoproject.com/en/2.2/ref/forms/fields/#django.forms.ModelMultipleChoiceField)

Si puedes dar un mejor ejemplo de lo que quieres hacer le podemos ayudar más.
Saludos.





El lun., 8 abr. 2019 a las 17:40, <tatianamesa687@gmail.com> escribió:
Hola, me gustaría saber de que manera se hace un update cuando tengo una relación de muchos a muchos en django, apreciaría mucho sus ayudas :)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/64971258-aa7b-4a4b-9532-94f0272e94a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
"La utopía sirve para caminar" Fernando Birri


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyM2J5y9WrUC9YPwJ6PeH6zNboJK%3D4hAScVDFAB%2B6vsMjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHAr%3D_21PiVzQD%2B_q5D-ynGmYffZB4YQjAaGmGJdPeNEvhKoUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment