Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django model example

from django.db import models

class myModel(models.Model):
  input1 = models.CharField(max_length=100)
  input2 = models.TextField()
  input3 - models.DateTimeField(auto_now=True)
  
  def __str__(self):
	return self.input1
Comment

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")
Comment

django model example

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()

class Publisher(models.Model):
    name = models.CharField(max_length=300)

class Book(models.Model):
    name = models.CharField(max_length=300)
    pages = models.IntegerField()
    price = models.DecimalField(max_digits=10, decimal_places=2)
    rating = models.FloatField()
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
    pubdate = models.DateField()

class Store(models.Model):
    name = models.CharField(max_length=300)
    books = models.ManyToManyField(Book)
Comment

PREVIOUS NEXT
Code Example
Python :: classification algorithms pythonb´ 
Python :: python loop 
Python :: amazon redshift 
Python :: adding numbers in python 
Python :: using shebang python 
Python :: list remove method in python 
Python :: checking length of sets in python 
Python :: pyqt matplotlib 
Python :: python startswith 
Python :: Python NumPy delete Function Syntax 
Python :: python code for internet radio stream 
Python :: lcd of 18 and 21 
Python :: how to avoid inserting duplicate records in orm django 
Python :: python all but the last element 
Python :: neat way to print 2d array 
Python :: How to Add a overall Title to Seaborn Plots 
Python :: get_queryset django rest framework 
Python :: server in python 
Python :: tree implementation in python 
Python :: is there a null data type in python 
Python :: connect and disconnect event on socketio python 
Python :: changes in settings.py for media storage without db 
Python :: creating a dictionary 
Python :: space complexity python 
Python :: python reverse range 
Python :: python print not working 
Python :: pytest monkeypatch 
Python :: python code variable declaration 
Python :: import csv in python 
Python :: python environment variable 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =