add lot management
This commit is contained in:
parent
aed2f3b40e
commit
bdb75ddf80
|
@ -22,4 +22,5 @@ urlpatterns = [
|
|||
path("", include("login.urls")),
|
||||
path("dashboard/", include("dashboard.urls")),
|
||||
path("device/", include("device.urls")),
|
||||
path("lot/", include("lot.urls")),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-08 13:55
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("device", "0003_remove_component_type_remove_computer_type_and_more"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Lot",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
("updated", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"type",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("Incoming", "Incoming"),
|
||||
("Outgoing", "Outgoing"),
|
||||
("Temporal", "Temporal"),
|
||||
],
|
||||
default="Temporal",
|
||||
max_length=32,
|
||||
),
|
||||
),
|
||||
("name", models.CharField(blank=True, max_length=64, null=True)),
|
||||
("code", models.CharField(blank=True, max_length=64, null=True)),
|
||||
("description", models.CharField(blank=True, max_length=64, null=True)),
|
||||
("closed", models.BooleanField(default=True)),
|
||||
("devices", models.ManyToManyField(to="device.device")),
|
||||
(
|
||||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,3 +1,23 @@
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from utils.constants import STR_SM_SIZE, STR_SIZE
|
||||
|
||||
# Create your models here.
|
||||
from user.models import User
|
||||
from device.models import Device
|
||||
|
||||
|
||||
class Lot(models.Model):
|
||||
class Types(models.TextChoices):
|
||||
INCOMING = "Incoming"
|
||||
OUTGOING = "Outgoing"
|
||||
TEMPORAL = "Temporal"
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
type = models.CharField(max_length=STR_SM_SIZE, choices=Types, default=Types.TEMPORAL)
|
||||
name = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
code = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
description = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
closed = models.BooleanField(default=True)
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
devices = models.ManyToManyField(Device)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
from lot import views
|
||||
|
||||
app_name = 'lot'
|
||||
|
||||
urlpatterns = [
|
||||
path("add/", views.NewLotView.as_view(), name="add"),
|
||||
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
|
||||
]
|
52
lot/views.py
52
lot/views.py
|
@ -1,3 +1,51 @@
|
|||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
UpdateView,
|
||||
)
|
||||
from dashboard.mixins import DashboardView, DetailsMixin
|
||||
from lot.models import Lot
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class NewLotView(DashboardView, CreateView):
|
||||
template_name = "new_lot.html"
|
||||
title = _("New lot")
|
||||
breadcrumb = "lot / New lot"
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
model = Lot
|
||||
fields = (
|
||||
"type",
|
||||
"name",
|
||||
"code",
|
||||
"description",
|
||||
"closed",
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
||||
class EditLotView(DashboardView, UpdateView):
|
||||
template_name = "new_lot.html"
|
||||
title = _("Update lot")
|
||||
breadcrumb = "Lot / Update lot"
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
model = Lot
|
||||
fields = (
|
||||
"type",
|
||||
"name",
|
||||
"code",
|
||||
"description",
|
||||
"closed",
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.object = get_object_or_404(self.model, pk=pk)
|
||||
# self.success_url = reverse_lazy('dashbiard:lot', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
|
Loading…
Reference in New Issue