(Sorry for my bad english i hope you can understand me) I have to make a multiple checkbox to select items of a query. But i can't make it work i try manually because i can't find info about how to make it using a form generated in forms.py.
This is what i need. I have WorkOrders and each order have diferent order movements.
This is the WorkOrders and order movements model.
class WorkOrder(models.Model):
fk_client = models.ForeignKey(Client, verbose_name='Cliente')
fk_store = models.ForeignKey(Store, verbose_name='Local')
store_internal_order = models.CharField(verbose_name='Orden Interna',
max_length=10,
null=True,
blank=True)
sector = models.IntegerField(verbose_name='Sector',
choices=SECTOR_CHOICES,
default=1)
article = models.CharField(verbose_name='Dispositivo', max_length=20)
serial = models.CharField(verbose_name='Serial', max_length=25)
work = models.CharField(verbose_name='Trabajo', max_length=40)
article_details = models.CharField(verbose_name='Detalles Artículo',
max_length=255, blank=True)
cash_advance = models.DecimalField(verbose_name='Seña', max_digits=6,
decimal_places=2,
default=0)
initial_price = models.DecimalField(verbose_name='Precio', max_digits=6,
decimal_places=2,
default=0)
service_cost = models.DecimalField(verbose_name='Costo', max_digits=6,
decimal_places=2,
default=0)
randpassw = models.CharField(default='12345', max_length=5, blank=True,
null=True)
warranty = models.PositiveSmallIntegerField(verbose_name='Garantía',
default=0,
blank=True,
null=True)
last_status = models.IntegerField(verbose_name='Estado',
choices=STATUS_CHOICES,
default=1)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
def __str__(self):
return str(self.id)
class OrderMovements(models.Model):
fk_workorder = models.ForeignKey(WorkOrder)
status = models.IntegerField(choices=STATUS_CHOICES, default=1)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
def __str__(self):
return str(self.fk_workorder)
and these are the choices
STATUS_CHOICES = (
(1, ("Orden Creada")),
(2, ("En Tienda Asociada")),
(3, ("Recibida en Cuyotek")),
(4, ("En Mesa de Trabajo")),
(5, ("Trabajo completado")),
(6, ("Sin Solución")),
(7, ("Lista para retirar en Cuyotek")),
(8, ("Lista para retirar en Tienda Asociada")),
(9, ("Es necesario contactar al cliente")),
(10, ("En espera de Repuestos")),
(20, ("ENTREGADA")),
)
SECTOR_CHOICES = (
(1, ("GAMES")),
(2, ("COMPUTERS")),
(3, ("PHONES")),
)
Well what i have to do is a view to add the Last Status "3" to a lot of orders of one Store and i'm doing this
def mass_movements(request, store_id):
if not request.user.is_authenticated():
return redirect('auth_login')
store = Store.objects.get(id=store_id)
orders = WorkOrder.objects.filter(fk_store=store_id)
title = "Movimientos en masa"
context = {
'title': title,
'store': store,
'orders': orders,
}
return render(request, "workorders/massmovements.html", context)
i recive all the orders of the store selected perfectly and i try this in the template i add a new colum in the table showing the results. with a input checkbox.
But i'm only recive the last checkbox i select even if i select a lot of them.
and i think this is not the best way to do this. i think maybe exist any way to do it.
What i been trying to do is get the lot of order.id selected in the checkbox and in the view make a for loop to add the ordermovement to each one. but i'm really stuck here.
Aucun commentaire:
Enregistrer un commentaire