***** want to share a pool of IP Addresses which are unique for both model Plc and model Station. Want to use Admin for adding Plc's and Stations. As is, if I try to use an IP address used within model PLC for another PLC it fails validation as expected. If I try to use an IP address assigned to a PLC in a new Station record, no error is displayed. I want a way to do this within the database design. I can do it as shown below for the station but don't know how to raise a native Admin error. The error shows up as a server error. Help
class Ip_addresses(models.Model): ip_addr=models.IPAddressField(unique=True) def __str__(self): return self.ip_addr class Plc(models.Model): name=models.CharField(max_length=30,unique=True) ip_addr=models.OneToOneField(Ip_addresses) #IPAddressField() ip_port=models.IntegerField(default=9600) plc_net=models.IntegerField(default=0) plc_node=models.IntegerField() plc_unit=models.IntegerField(default=0) def __unicode__(self): return self.name class Admin: pass class Station(models.Model): DEV_TYPE=( ('friend','friend'), ('user','user'), ('peer','peer')) HOST_TYPE=( ('static','static'), ('dynamic','dynamic')) DTMF_MODE=( ('rfc2833','rfc2833'), ('inband','inband')) dev_name=models.CharField(max_length=30,unique=True) dev_type=models.CharField (max_length=30,choices=DEV_TYPE,default='friend') ip_addr=models.OneToOneField(Ip_addresses) #IPAddressField() host=models.CharField (max_length=20,choices=HOST_TYPE,default='static') secret=models.CharField(max_length=20,default='1234') dtmf_mode=models.CharField (max_length=20,choices=DTMF_MODE,default='rfc2833') mailbox=models.CharField(max_length=40,default='0') context=models.CharField(max_length=40) callerid=models.CharField(max_length=80) def __str__(self): return self.dev_name def save(self): from extensions.models import Plc from django.http import HttpResponse try: p=Plc.objects.get(ip_addr=self.ip_addr) except ObjectDoesNotExist: self.context=self.dev_name super(Station,self).save() else: raise Exception("IP Address used by PLC") class Admin: pass --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---