Re: Django Admin interface and filter by value

2010-01-24 Thread Peter Bengtsson
Sounds like something you'd have to do with javascript by extending
the admin interface's templates.
Any other default values are best done by settings up signals for your
User class.

On a more general, yet important note, I would strongly advice against
making your own User model unless you really know what you're doing.
Use the User model inside Django and just let that be what it is. All
other bits and pieces such as MacAddress is then put in a user profile
class. There's good documentation on how to control your user profiles
and how that works.

On Jan 22, 11:42 am, onorua  wrote:
> 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.



Django Admin interface and filter by value

2010-01-22 Thread onorua
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.