rom django.db import models
from django.conf import settings
from django.urls import reverse
class ModelsAuto(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Brands(models.Model):
name = models.CharField(max_length=100)
model_auto = models.ForeignKey(
ModelsAuto, on_delete=models.CASCADE
)
def __str__(self):
return self.name
class Claim(models.Model):
chassis_number = models.CharField(max_length=100)
vin_number = models.CharField(max_length=17)
model_auto = models.ForeignKey(
ModelsAuto, null=True, on_delete=models.SET_NULL
)
brand_auto = models.ForeignKey(
Brands, null=True, on_delete=models.SET_NULL
)
mileage = models.IntegerField(null=True)
condition_auto = models.CharField(max_length=255)
description_failure = models.TextField()
result_check = models.CharField(max_length=255)
dtc_codes = models.CharField(max_length=255)
text_claim = models.TextField()
date_claim = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
def __str__(self):
return self.text_claim
def get_absolute_url(self):
return reverse(
'claim_detail', args=[str(self.id)]
)
...
class ClaimCreateView(CreateView):
model = models.Claim
fields = [
'author',
'chassis_number',
'vin_number',
'model_auto',
'brand_auto',
'mileage',
'condition_auto',
'description_failure',
'result_check',
'dtc_codes',
'text_claim',
]
template_name = 'claim_new.html'
{% extends 'base.html' %}
{% block content %}
<h1>Новое сервисное задание</h1>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-success ml-2" type="submit">Сохранить</button>
</form>
{% endblock content %}