How to get a product ID by accessing a product file

I have a file that is part of a product, I need to automate a file attribute (partnumber) that asks for a product attribute, how can I access this information?

My models.py:

class Produto(models.Model):
    ...
    tipoProduto = ForeignKey(TipoProduto, ...)
    ...

class Arquivo(models.Model):
    revisao = IntegerField()
    nome = CharField(max_length=30)
    tipo = CharField(max_length=4, choices=tipoArquivo)
    tipoArquivo = CharField(max_length=15, choices=tipoArquivoSLD)
    partNumber = CharField(max_length=16, null=True, blank=True)
    tipoFabricacao = CharField(max_length=25, choices=tipoFabricacaoChoice)
    file = models.FileField(upload_to=filePath)

my views.py:

def GetPartNumber(request, id):
    partnumberForm = PartNumberForm()
    file = Arquivo.objects.get(id=id)
    if request.method == 'POST':
        partnumberForm = PartNumberForm(request.POST or None)
        if partnumberForm.is_valid():
            pt = partnumberForm.save(commit=False)
            productTip = 'GC'
            sldTip = file.tipoArquivo
            cod = PartNumber.objects.get()
            year = datetime.date.today().year
            pt = str(productTip) + str(sldTip) + str(cod) + '-' + str(year)
            pt.save()
    context={'partnumberForm':partnumberForm}
    return render(request, 'produtos/NewPartNumber.html', context)

Back to Top