I have two models:

class User(models.Model):

    LoginName = models.CharField('login', max_length=50)
    Email = models.EmailField('e-mail', blank=True)
    FirstName = models.CharField(max_length=50)
    LastName = models.CharField(max_length=50)
    IpAddress = models.IPAddressField(unique=True)
    MacAddress = models.CharField(max_length=17)
    UserAddress = models.CharField(max_length=250)
    Switch = models.ForeignKey('Switch')
    Port = models.ForeignKey('Port')


class Switch(models.Model):
    SwitchTypes = (
        ('N', 'Non managed'),
        ('M', 'Managed'),
        ('3', '3 Layer'),
        )
    SwitchSNMP = (
        ('Y', 'Yes'),
        ('N', 'No'),
        )
    Name = models.CharField( max_length=50)
    IpAddress = models.IPAddressField('unique=True)
    Location = models.CharField(max_length=250)
    Manufacture = models.CharField(max_length=50)
    Model = models.CharField(max_length=50)
    PortsNumber = models.IntegerField()
    Type = models.CharField(max_length=1, choices=SwitchTypes)
    SNMP_enable = models.CharField( max_length=1, choices=SwitchSNMP)
    SNMP_group = models.CharField(max_length=50, blank=True)
    def __unicode__(self):
        return ('%s %s' % (self.Name, self.IpAddress))

class Port(models.Model):
    MediaType = (
        ('C', 'Copper'),
        ('F', 'Fiber'),
        )

    Type = models.CharField(max_length=1, choices=MediaType)
    MaxSpeed = models.SmallIntegerField(default = 100)
    CurSpeed = models.SmallIntegerField(default=100)
    Switch = models.ForeignKey('Switch')
    PortNum = models.SmallIntegerField()
    Description =  models.CharField(max_length=250, blank=True)

    def __unicode__(self):
        return ('%s ' % (self.PortNum))


I would like to have following:
1. When I create a new user, I choose switch from the list of
available switches, and when I go to the Port, it will automatically
shows only Ports for this particular switch.
2. When I add a new Switch, and put the port number as 16, they would
be automatically crated with the default values.

Is it possible to do? Could you please point me out on the elegant
solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to