Skip to content

Commit

Permalink
Add first version of devices model with admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Oct 3, 2024
1 parent c3350db commit b3c6681
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 0 deletions.
Empty file added devices/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions devices/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import DeviceModel, Device

# Register your models here.
admin.site.register(DeviceModel)
admin.site.register(Device)

6 changes: 6 additions & 0 deletions devices/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DevicesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'devices'
45 changes: 45 additions & 0 deletions devices/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.2.16 on 2024-10-03 16:14

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='DeviceModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('manufacturer', models.CharField(max_length=100)),
('version', models.CharField(blank=True, max_length=50, null=True)),
('max_radiation_range', models.FloatField(help_text='Maximum radiation range the device can measure (in appropriate units)')),
],
),
migrations.CreateModel(
name='Device',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('serial_number', models.CharField(max_length=100, unique=True)),
('hash', models.CharField(max_length=64, unique=True)),
('purchase_date', models.DateField(blank=True, null=True)),
('calibration_date', models.DateField(blank=True, null=True)),
('is_active', models.BooleanField(default=True)),
('device_model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='devices.devicemodel')),
('owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Device',
'verbose_name_plural': 'Devices',
'ordering': ['serial_number'],
},
),
]
Empty file added devices/migrations/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions devices/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.db import models
from django.contrib.auth.models import User # Assuming you're using Django's User model for owners

class DeviceModel(models.Model):
"""
Represents the different models of devices used for gamma radiation measurement.
"""
name = models.CharField(max_length=100) # Name of the device model
manufacturer = models.CharField(max_length=100) # Manufacturer of the device
version = models.CharField(max_length=50, blank=True, null=True) # Optional version of the device model
max_radiation_range = models.FloatField(help_text="Maximum radiation range the device can measure (in appropriate units)")

def __str__(self):
return f"{self.name} (by {self.manufacturer})"

class Device(models.Model):
"""
Represents an individual gamma radiation measurement device.
"""
device_model = models.ForeignKey(DeviceModel, on_delete=models.CASCADE) # Link to the DeviceModel
serial_number = models.CharField(max_length=100, unique=True) # Unique identifier for the device (serial number)
hash = models.CharField(max_length=64, unique=True) # Unique hash for the device (for identification)
owner = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) # Owner of the device
purchase_date = models.DateField(blank=True, null=True) # Optional field for when the device was purchased
calibration_date = models.DateField(blank=True, null=True) # Date of the last calibration
is_active = models.BooleanField(default=True) # Indicates if the device is still in use

def __str__(self):
return f"Device {self.serial_number} ({self.device_model.name})"

class Meta:
verbose_name = "Device"
verbose_name_plural = "Devices"
ordering = ['serial_number']
3 changes: 3 additions & 0 deletions devices/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions devices/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
3 changes: 3 additions & 0 deletions openred/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',

# Custom apps
'devices',
]

MIDDLEWARE = [
Expand Down

0 comments on commit b3c6681

Please sign in to comment.