Answers for "Django primary key model"

3

primary key django model

class Garden(models.Model):
    garden_id = models.IntegerField(primary_key=True)
Posted by: Guest on April-29-2020
-1

django custom primary key field

import uuid
from django.db import models

class MyUUIDModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # other fields
Posted by: Guest on May-04-2021
0

django composite primary key

#Try similar below code:

class MyTable(models.Model):
    class Meta:
        unique_together = (('key1', 'key2'),)

    key1 = models.IntegerField(primary_key=True)
    key2 = models.IntegerField()
#or if you want only unique mixed fields:

class MyTable(models.Model):
    class Meta:
        unique_together = (('key1', 'key2'),)

    key1 = models.IntegerField()
    key2 = models.IntegerField()
Posted by: Guest on August-26-2021

Code answers related to "Django primary key model"

Python Answers by Framework

Browse Popular Code Answers by Language