1

我正在尝试实现 Django站点地图,并希望在我的站点地图更新时使用 ping google。每当将新的医生条目添加到数据库时,我对如何在我的模型中编写保存方法有点困惑。

这是我的 models.py 文件

class Doctor(models.Model):
    name = models.CharField(max_length=1300)
    specialization = models.ForeignKey(Specialization)
    clinic = models.ForeignKey(Clinic)
    seekers = models.ManyToManyField(User, through='UserContent')
    language = models.ManyToManyField(Language)
    scope = models.CharField(max_length=1300, null = True, blank = True)
    education1 = models.CharField(max_length=1300)
    gender_choices = ( ('Male', 'Male'), ('Female','Female'),)
    gender = models.CharField(max_length=15, choices = gender_choices, null=True, blank = True)
    image = models.ImageField(upload_to='uploads/', null=True, blank = True)
    mimetype = models.CharField(max_length=20)
    submitted_on = models.DateTimeField(auto_now_add=True, null = True, blank = True)

def __unicode__(self):
  return u"%s %s" % (self.name, self.specialization)


def get_absolute_url(self):
    from django.core.urlresolvers import reverse
    return reverse('meddy1.views.showDocProfile', args=[str(self.id)])
4

1 回答 1

0

不要覆盖保存方法。更好的是,使用信号,更具体地说,使用 post_save 信号。

于 2014-08-15T19:24:01.470 回答