Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django model

class Video(models.Model):
   title = models.CharField(max_length=200, null=True, blank=True)
   description = models.TextField(null=True, blank=True)
   url = models.CharField(max_length=200, null=True, blank=True)
   video_id = models.CharField(max_length=200, null=True, blank=True)
   created_at = models.DateTimeField(auto_now_add=True)
   updated_at = models.DateTimeField(auto_now=True)

   def __str__(self):
      return self.title
Copy
Comment

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 :: numpy concatenation python 
Python :: bar plot python 
Python :: assert integer python 
Python :: django template render dict 
Python :: matplot lib 3d plot autoscale 
Python :: use a csv file on internet as an api in python 
Python :: python do while loop 
Python :: default values python 
Python :: python 2.7 get user input 
Python :: username python system 
Python :: colorgram in python 
Python :: plt delete space before axis 
Python :: how to change values in dataframe python 
Python :: eval function in python 
Python :: python milisegundos 
Python :: python telegram bot login 
Python :: pop list python 
Python :: update all pip packages 
Python :: python string replace variable 
Python :: sort dict of dicts by key 
Python :: pandas df by row index 
Python :: python for dummies 
Python :: getting size of list in python 
Python :: python set python key default 
Python :: discord.py get user id 
Python :: pandas dataframe row names 
Python :: lowercase python 
Python :: python sort descending 
Python :: python get names of input arguments 
Python :: ipython history 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =