Django Model Methods
Bu eğitimimizde Django Model Methods konusunu işledik.
class Article(models.Model):
title = models.CharField(max_length=50,verbose_name="Başlık")
description = models.TextField(max_length=5000,verbose_name="Açıklama")
created_date = models.DateTimeField(auto_now_add=True,verbose_name="Oluşturulma Tarihi")
modified_date = models.DateTimeField(auto_now=True,verbose_name="Düzenlenme Tarihi")
category = models.ManyToManyField(to="articles.Category")
author = models.ForeignKey(Kullanici,on_delete=models.CASCADE,verbose_name="Yazar",null=True)
def title_guncelle(self,title:str):
self.title = title
self.save()
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
super(Article, self).save()
def delete(self, using=None, keep_parents=False):
super(Article, self).delete()
class Meta:
db_table = "Makaleler"
verbose_name = "Makale"
verbose_name_plural = "Makaleler"
ordering = ("-created_date",)
def __str__(self):
return self.title
Yorumlar
Henüz Hiç Yorum Yapılmamış