Only have one instance of the django model

I only need one instance of the model below. How to do this in code?

class Employer(models.Model): name=models.CharField(max_length=50, verbose_name = "Employer Name") pin =models.CharField(max_length=50, verbose_name ="Employer PIN") def __unicode__(self): return self.name 
+4
source share
1 answer

try the following:

 class Employer(models.Model): name = models.CharField(max_length=50, verbose_name="Employer Name") pin = models.CharField(max_length=50, verbose_name="Employer PIN") def __unicode__(self): return self.name class Meta: unique_together = ('name', 'pin') 

from Django Metadata Options .

+2
source

Source: https://habr.com/ru/post/1414722/


All Articles