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 1

    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