-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first version of devices model with admin panel
- Loading branch information
Showing
9 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters