#2 Сортировка полей в моделях

Open
blezz-tech wants to merge 1 commits from blezz-tech/sorting-fields-of-models into ShariX_Open/master
4 changed files with 19 additions and 11 deletions
  1. 5 2
      models/attachment.py
  2. 4 5
      models/comment.py
  3. 7 4
      models/ticket.py
  4. 3 0
      models/ticket_list.py

+ 5 - 2
models/attachment.py

@@ -11,11 +11,14 @@ def get_attachment_upload_dir(instance, filename):
 
 
 class Attachment(models.Model):
-    ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
-    added_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
+    # DATA
     timestamp = models.DateTimeField(auto_now_add=True)
     file = models.FileField(upload_to=get_attachment_upload_dir, max_length=255)
 
+    # FK
+    ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
+    added_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
+
     def filename(self):
         return os.path.basename(self.file.name)
 

+ 4 - 5
models/comment.py

@@ -7,15 +7,14 @@ from tickets.models.ticket import Ticket
 
 
 class Comment(models.Model):
-    author = models.ForeignKey(
-        get_user_model(), on_delete=models.CASCADE, blank=True, null=True,
-        related_name="tickets_comments"
-    )
+    # DATA
+    author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, blank=True, null=True, related_name="tickets_comments")
     ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
+
+    # FK
     date = models.DateTimeField(auto_now_add=True)
     email_from = models.CharField(max_length=320, blank=True, null=True)
     email_message_id = models.CharField(max_length=255, blank=True, null=True)
-
     body = models.TextField(blank=True)
 
     class Meta:

+ 7 - 4
models/ticket.py

@@ -78,19 +78,22 @@ class Ticket(models.Model):
     TICKET_TYPES_CHOICES = tuple((item[0], item[1]) for item in TICKET_TYPES)
     LIFE_CYCLE_DICT = dict((item[0], item[2]) for item in TICKET_TYPES)
 
+    # DATA
     title = models.CharField(max_length=128)
-    ticket_list = models.ForeignKey(TicketList, on_delete=models.CASCADE)
-    ticket_type = models.PositiveSmallIntegerField(choices=TICKET_TYPES_CHOICES, default=1)
     status = models.PositiveSmallIntegerField(null=True)
     created_at = models.DateTimeField(auto_now_add=True, editable=False)
     updated_at = models.DateTimeField(auto_now=True)
     due_date = models.DateField()
-    created_by = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, related_name="created_by", editable=False)
-    assigned_to = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True, related_name="assigned_to")
     note = models.TextField(blank=True, null=True)
     json = models.TextField(blank=True, null=True)
     priority = models.PositiveSmallIntegerField(default=0)
 
+    # FK
+    created_by = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, related_name="created_by", editable=False)
+    assigned_to = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True, related_name="assigned_to")
+    ticket_list = models.ForeignKey(TicketList, on_delete=models.CASCADE)
+    ticket_type = models.PositiveSmallIntegerField(choices=TICKET_TYPES_CHOICES, default=1)
+
     def __str__(self):
         return self.title
 

+ 3 - 0
models/ticket_list.py

@@ -3,7 +3,10 @@ from django.db import models
 
 
 class TicketList(models.Model):
+    # DATA
     name = models.CharField(max_length=128)
+
+    # FK
     group = models.ForeignKey(Group, on_delete=models.CASCADE)
 
     def __str__(self):