V
V
Victor Corvus2021-04-28 23:16:15
Django
Victor Corvus, 2021-04-28 23:16:15

How to separate part of a variable in django models?

Hello, I'm new to Django, I'm writing a simple website for checking barcodes through a checker connected via API. A barcode is entered into the database (PostgreSQL), you need to separate a part from the barcode (2 digits) and send it to the checker, how to do this?

from django.db import models
 
 
class Product(models.Model):
    QR = models.CharField(max_length=255, default='0')
 
    class Meta:
      verbose_name_plural = "QR"
 
    def __str__(self):
        return self.name

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-04-29
@imosom

you need to separate the part from the barcode (2 digits)

Read about slices
class Product(models.Model):
QR = models.CharField(max_length=255, default='0')
class Meta:
verbose_name_plural = "QR"
def __str__(self):
return self.name

It is not clear what the model is given to, and where self.name comes from.

M
maksam07, 2021-04-29
@maksam07

I may be wrong, but if you are new to django, why are you working on tasks that require non-basic knowledge? Take a few lessons on site building in Django

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question