我正在尝试在管理员中添加一个“事件”并收到此错误:
/admin/sms/event/add/ 'Contact' 对象的 TypeError 不可下标
models.py:
class Contact(models.Model):
users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name="contact")
name = models.CharField(_("Recipient"), max_length=40)
phone = models.IntegerField(_("Phone"), max_length=10)
def __unicode__(self):
return "%s: %d" % (self.name, self.phone)
class Event(models.Model):
calendar = models.ForeignKey(Calendar, verbose_name=_("Calendar"), related_name="event_calendar")
message = models.ForeignKey(Message, verbose_name=_("Message"), related_name="event_message")
recipient = models.ForeignKey(Contact, verbose_name=_("Recipient"), related_name="event1")
event_date = models.DateField(_("Date"))
start_time = models.TimeField(_("Start time"))
end_time = models.TimeField(_("End time"), blank=True, null=True)
location = models.CharField(_("Location of meeting"), blank=True, null=True, max_length=100)
reminder_options = models.IntegerField(choices=ReminderOptions.CHOICES, verbose_name=_("Reminder time"))
content = models.CharField(_("Event Notes"), max_length=160)
# recurring_options = models.IntegerField(choices=RecurringOptions.CHOICES, verbose_name=_("Recurring time"))
def __unicode__(self):
return self.recipient
def get_absolute_url(self):
return u'/create-event/'