Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django change id to uuid

4

this can be done by using a custom base abstract model,using the following steps.

First create a folder in your project call it basemodel then add a abstractmodelbase.py with the following below:
from django.db import models
import uuid


class BaseAbstractModel(models.Model):

    """
     This model defines base models that implements common fields like:
     created_at
     updated_at
     is_deleted
    """
    id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False)
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    updated_at = models.DateTimeField(auto_now=True, editable=False)
    is_deleted = models.BooleanField(default=False)

    def soft_delete(self):
        """soft  delete a model instance"""
        self.is_deleted=True
        self.save()

    class Meta:
        abstract = True
        ordering = ['-created_at']
Comment

django change id to uuid

from django.db import models
from basemodel import BaseAbstractModel
import uuid

# Create your models here.

class Incident(BaseAbstractModel):

    """ Incident model  """

    place = models.CharField(max_length=50, blank=False, null=False)
    personal_number = models.CharField(max_length=12, blank=False, null=False)
    description = models.TextField(max_length=500, blank=False, null=False)
    action = models.TextField(max_length=500, blank=True, null=True)
    image = models.ImageField(upload_to='images/', blank=True, null=True)
    incident_date = models.DateTimeField(blank=False, null=False)
Comment

django change id to uuid

from django.db import models
import uuid


class BaseAbstractModel(models.Model):

    """
     This model defines base models that implements common fields like:
     created_at
     updated_at
     is_deleted
    """
    id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False)
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    updated_at = models.DateTimeField(auto_now=True, editable=False)
    is_deleted = models.BooleanField(default=False)

    def soft_delete(self):
        """soft  delete a model instance"""
        self.is_deleted=True
        self.save()

    class Meta:
        abstract = True
        ordering = ['-created_at']
Comment

django change id to uuid

4

this can be done by using a custom base abstract model,using the following steps.

First create a folder in your project call it basemodel then add a abstractmodelbase.py with the following below:
from django.db import models
import uuid


class BaseAbstractModel(models.Model):

    """
     This model defines base models that implements common fields like:
     created_at
     updated_at
     is_deleted
    """
    id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False)
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    updated_at = models.DateTimeField(auto_now=True, editable=False)
    is_deleted = models.BooleanField(default=False)

    def soft_delete(self):
        """soft  delete a model instance"""
        self.is_deleted=True
        self.save()

    class Meta:
        abstract = True
        ordering = ['-created_at']
Comment

PREVIOUS NEXT
Code Example
Python :: How can I get the output of each layer in Tensorflow 2 
Python :: time in python 
Python :: python re split 
Python :: find each geometry overlap python 
Python :: Set path for another directory 
Python :: .unique() python 
Python :: flattern in keras 
Python :: how to count the number of guesses in python 
Python :: pandas set one column equal to another 
Python :: python docker 
Python :: DIF_GCD solution 
Python :: The options auto_now, auto_now_add, and defa ult are mutually exclusive. Only one of these options may be present. 
Python :: accessing a variable from outside the function in python 
Python :: how to find a specific word in a list python 
Python :: Lucky four codechef solution 
Python :: how to step or only print every two element of list python 
Python :: pahtlib join path 
Python :: how to remove last item from list python 
Python :: Split a list based on a condition 
Python :: repl.it install packages python 
Python :: create hasmap in python 
Python :: read excel file in computer 
Python :: concatenacion python 
Python :: How to Replace substrings in python 
Python :: current date to midnight 
Python :: flask multuple parameters 
Python :: import file in another path python 
Python :: set time complexity python 
Python :: spliting the text to lines and keep the deliminaters python 
Python :: round to decimal places python 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =