J'ai 3 modèles Matériel, UDM, BIN_UOMobjet 'QuerySet' n'a pas d'attribut '- numéro Django ORM
@with_author
class Material(models.Model):
version = IntegerVersionField()
code = models.CharField(max_length=30)
name = models.CharField(max_length=30)
slug = models.SlugField(max_length=80, blank=True)
description = models.TextField(null=True, blank=True)
materialuom = models.CharField(max_length=1,
choices=UOM_CHOICES)
creation_time = models.DateTimeField(auto_now_add=True, blank=True)
itemgroup = models.ForeignKey(ItemGroup, on_delete=models.PROTECT)
keywords = models.CharField(max_length=50,null=True, blank=True)
valid_from = models.DateTimeField(null=True, blank=True)
valid_to = models.DateTimeField(null=True, blank=True)
min_quantity = models.DecimalField(max_digits=19, decimal_places=10)
trigger_quantity = models.DecimalField(max_digits=19, decimal_places=10)
max_quantity = models.DecimalField(max_digits=19, decimal_places=10)
@with_author
class UOM(models.Model):
version = IntegerVersionField()
code = models.CharField(max_length=30)
name = models.CharField(max_length=30)
material = models.ForeignKey(Material)
description = models.TextField(null=True, blank=True)
@with_author
class UOM_BINUOM(models.Model):
version = IntegerVersionField()
UOM = models.ForeignKey(UOM)
BIN_UOM = models.ForeignKey(BIN_UOM)
quantityperunit = models.PositiveSmallIntegerField()
creation_time = models.DateTimeField(auto_now_add=True,blank=True)
Sur l'entrée, j'ai mon ID matériel
En utilisant ORM django Je veux obtenir tous les objets de UOM_BINUOM de mon identifiant matériel.
Dans SQL:
Select * from UOM_BINUOM where UOM_BINUOM.uom in (Select uom from UOM where UOM.material = material)
En ORM Je suis en train de comme ceci:
uombinuom = UOM.objects.filter(material__in=material_id).uom_binuom_set.all().order_by('-id')
ou comme celui-ci
material = get_object_or_404(Material, pk=material_id)
uom = material.uom_set.all().order_by('-id')
uombinuom = uom.uom_binuom_set.all().order_by('-id')
mais obtenir erreur
« QuerySet 'objet n'a pas d'attrib Qu'est-ce que je fais mal et comment puis-je résoudre ce problème?
Est-ce que 'material_id' est une liste d'ID ou un ID unique? – Alasdair
material_id est ID unique –