Answer the question
In order to leave comments, you need to log in
Why is the number of users in the DB not the same as the number of User.pk? (Signals)?
I have a Customer model:
class Customer(models.Model):
user = models.ForeignKey(User, verbose_name='Пользователь', on_delete=models.CASCADE, blank=True, null=True)
avatar = models.ImageField("Аватар", blank=True, null=True)
date = models.DateField("Дата создания", auto_now=True, auto_now_add=False, blank=True, null=True)
id_num = models.PositiveIntegerField(verbose_name='id-номер', null=True, blank=True)
@receiver(post_save, sender=User)
def created_user_profile(sender, instance, created, **kwargs):
if created:
Customer.objects.create(user=instance, id_num=instance.pk)
@receiver
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
Answer the question
In order to leave comments, you need to log in
Read about how auto- increment works in a database (or rather, a whole course / book on database and sql architecture).
If id_num means the client's serial number and it must be without gaps, then you definitely cannot use an id based on autoincrement for this, the order must be guaranteed on your own. A lot of people stepped on it, you're another.
Dr. Bacon , Yes, I'm aware, I wanted to make a binding by slug, but I don't know how, when adding, let's say from the username field to the slug field, the entered data from the user would be automatically translated into English characters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question