Thursday, March 31, 2011

best way to define a many-to-one relationship using FreeRadius' existing DB schema

Thanks in advance for any insight or suggestions.

I have a simple web interface for a freeradius mysql database. It
uses the Django admin interface exclusively, and makes it simple to
manage Radius usernames, passwords, preferences etc, which we use for
authentication on WiFi hotspots.

My question - how can I best use "models.ForeignKey" to associate
freeradius accounting data with the "WifiUser" I am using to manage
radius usernames/passwords/etc?

Here's a portion of the WifiUser model:

class WifiUser(models.Model):
username = models.CharField( max_length=64,
unique=True )
password = models.CharField( max_length=64 )
# Radius attributes -see http://coova.org/CoovaChilli/Proxy#toc6
session_timeout = models.CharField( max_length=64, blank=True,
default='21600' )
# These point to entries in freeradius db tables
radius_password = models.OneToOneField(RadiusPassword,
editable=False)
radius_session_timeout = models.OneToOneField(RadiusSessionTimeout,
editable=False)

I then use Signals to update the appropriate freeradius db tables as
necessary (e.g., WifiUser.password is changed, the new value is also
stored in WifiUser.radius_password.value) - it works great, thank you
Django.

What I would like to do is have access to a WifiUser's radius
accounting data via the Django Admin interface.
This table looks like:

CREATE TABLE `radacct` (
`radacctid` bigint NOT NULL PRIMARY KEY,
`username` varchar(192) NOT NULL,
bunch of cool radius info logged per session
--snip--
So the radacct.username == WifiUser.username - but that is all I've
got to associate these two tables.

Can I set up some customized version of this Many-to-One relationship
-
class RadiusAccounting(models.Model):
wifiuser = models.ForeignKey('WifiUser')

in which I specify that "RadiusAccounting.username ==
WifiUser.username" instead of
"RadiusAccounting.wifiuser_id == WifiUser.id: -- thus reaping the
benefits of a normal ForeignKey relationship?

Regards,
Todd

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment