Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django model functions

from django.db import models

class Book(models.Model):
    title = models.CharField(max_length=100)

    @classmethod
    def create(cls, title):
        book = cls(title=title)
        # do something with the book
        return book

book = Book.create("Pride and Prejudice")
Source by docs.djangoproject.com #
 
PREVIOUS NEXT
Tagged: #django #model #functions
ADD COMMENT
Topic
Name
8+6 =