How in django can I limit the number of records that can be in the database? So that, for example, if the number of entries is maximum, it was impossible to add more entries through the admin panel (through it).
1 answer
class SomeModel: ... def save(self, *args, **kwargs): if SomeModel.objects.count() < settings.MAX_SOMEMODEL_COUNT: super().save(*args, **kwargs) raise ValidationError('Π‘Π»ΠΈΡΠΊΠΎΠΌ ΠΌΠ½ΠΎΠ³ΠΎ Π·Π°ΠΏΠΈΡΠ΅ΠΉ ΡΠΈΠΏΠ° SomeModel!') - Manager is not accessible via ShortInfoAboutCompany instances - This is what happens - Antoxer
- Corrected. And so? - Sergey Gornostaev
- It worked. Thank you very much :) - Antoxer
|