Answer the question
In order to leave comments, you need to log in
How to check if the generated value exists in another Django db table?
there are 2 models:
class U (models.Model):
id = models.AutoField(primary_key=True)
created_at = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=3000, blank=True, null=True)
name = models.CharField(max_length=18, null=True, blank=True)
class U_blocked (models.Model):
name_blocked = models.CharField(max_length=18, help_text="блокированный")
Answer the question
In order to leave comments, you need to log in
if U_blocked.objects.filter(name_blocked=cleaned_data.get('name')).exists():
raise ValidationError
If I understand everything correctly, then you need to prevent adding records with text from the "locked" table to the database.
Try adding a check in the pre_save
signal. Here is an example mechanism.
https://stackoverflow.com/a/6462188
If you need to prevent save - just throw an exception.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question