Created
March 27, 2017 21:19
-
-
Save MandarGogate/54aa781bc0eb22737f803bbf17f26d88 to your computer and use it in GitHub Desktop.
Limit a single record in model for Django App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel(models.Model): | |
onefield = models.CharField('The field', max_length=100) | |
class MyModelAdmin(admin.ModelAdmin): | |
def has_add_permission(self, request): | |
# if there's already an entry, do not allow adding | |
count = MyModel.objects.all().count() | |
if count == 0: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would be better