I want only one instance of the model below. How can I enforce this in code?
class Employer(models.Model):
name=models.CharField(max_length=50, verbose_name = "Employer's Name")
pin =models.CharField(max_length=50, verbose_name ="Employer's PIN")
def __unicode__(self):
return self.name
try this:
class Employer(models.Model):
name = models.CharField(max_length=50, verbose_name="Employer's Name")
pin = models.CharField(max_length=50, verbose_name="Employer's PIN")
def __unicode__(self):
return self.name
class Meta:
unique_together = ('name', 'pin')
from Django Model Meta options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With