class About(models.Model): short_description = models.Textfield() description = models.Textfield() image = models.ImageField(upload_to='about') class Meta: verbose_name = 'About me' verbose_name_plural = 'About me' def __str__(self): return 'About me'
class Podcast(models.Model): Id = models.Integerfield(blank=False, null=False) Name = models.Charfield(max_length=100, null=False, blank=False) Duration = models.Decimalfield(max_digits=4, decimal_places=2, blank=False) Uploaded time = models.Integerfield(datetime.Datetime, blank=False) Host = models.Charfield(max_length=100, blank=False) Participants = models.Textfield(max_length=100, blank=True, end={''})
class Meals(models.Model): name = models.CharField(max_length=50) description = models.Textfield(max_length=500) people = models.IntegerField() price = models.DecimalField(max_digits=5, decimal_places=2) preparation_time = models.IntegerField() image = models.ImageField(upload_to='meals/')
class Package(models.Model): name = models.CharField(maxlength=300) version = models.CharField(maxlength=300, blank=True) home_page = models.URLField(blank=True) summary = models.TextField() description = models.TextField(blank=True) keywords = models.Textfield(blank=True) categories = models.ManyToManyField(Category, related_name="packages")
class Comment(models.Model): comment = models.Textfield() post = models.ForeignKey(Post, related_name="comments") user = models.ForeignKey(User, related_name="users") likes = models.ManyToManyField(User, related_name="comments_liked") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = CommentManager()
class Company(models.Model): name = models.Charfield(max_length=250) estd = models.DateTimeField(default=timezone.now) date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) description = models.Textfield() vat_number = models.CharField(max_length=40, blank=False, null=False) address = models.CharField(max_length=300)
class Job(models.Model): name = models.CharField(max_length=255) location = models.CharField(max_length=255) description = models.Textfield() creator = models.ForeignKey(User, related_name="job_created") acceptor = models.ForeignKey(User, related_name="job_accepted", null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)
class Company(models.Model): company_name = models.CHARFIELD(max_length=200) category = subcategory = company_url = company_description = models.Textfield() created_date = models.DateTimeField(default=timezone.now) def publish(self): self.save() def __str__(self): return self.company_name
IN VIEWS: def create(request): if request.method == "POST" request.session['name'] = request.POST['first_name'] return redirect(/) IN HTML {{request.session.name}} MODELS: from django.db import models # Create your models here. class User(models.Model): #Class tends to be singular first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) description = models.TextField() #No limit created_at = models.DateTimeField(auto_now_add=True) #will add time at creation once updated_at = models.DateTimeField(auto_now=True) #will add time everytime it updates if "User" can have many of another class: One to Many Relationship like users to posts: Create a second class in models class Post(models.Model):djan title = models.Charfield(max_length=45) message = models.Textfield(max_length=1000) user_id = models.ForeignKey(User) #This connects the class "Post" to class "User" (one to many) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) url(r'^users/(?P<id>)\d+)$', views.show)
class MeetingType(models.Model): meetingtitle=models.Charfield (max_length='64') meetingdate=models.Datefield() meetingtime=models=models.Integer(max_length = '4') meetinglocation==models.Charfield (max_length='256') meetingagenda=models.Textfield()
class Post(models.Model): author_name - models.CharField(max_length=20) title = models.CharField(max_length=100) content = models.Textfield() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)
class curso(models.Model): descripcion = models.Textfield() Asignatura = models.ManyToManyField(Asignatura)
class tipo(models.Model): nombre = models.Textfield()
class Item(models.Model): text = models.Textfield()