0

我的会议模型在这里

class Meeting(models.Model):
    name = models.CharField(max_length=200)
    meetingID = models.CharField(max_length = 50) 
    venue = models.ForeignKey('MeetingRoom',related_name ='meetingroom',null = True,blank = True)   # whether One Time or Recurring
    status =models.IntegerField(null=True, blank=True)
    recurring_time = models.CharField(max_length=50)              # (Recurring date schedule information)
    attendee_passwd = models.CharField(max_length=100)
    moderator_passwd = models.CharField(max_length = 100)
    date_created = models.DateTimeField(auto_now=True)               # it should be auto fill 

    meeting_datetime = models.DateTimeField(default=datetime.datetime.now,blank=True, null=True)
    timezone = models.CharField(max_length = 50)
    reminder = models.BooleanField()
    start_time = models.CharField(max_length=100)
    end_time = models.CharField(max_length=100)
    meeting_duration = models.CharField(max_length=100)

    duration = models.CharField(max_length=20)
    created_by = models.ForeignKey('User',related_name ='meetingroom_created')
    sms_no = models.IntegerField()  #participant will call on this number   Unique for all users and participant 
    conferenceID = models.IntegerField(blank=True, null=True)
    meeting_logout_url = models.CharField(max_length=100)
    max_participants = models.IntegerField(blank=True, null=True)
    participants = models.ForeignKey('Participant',related_name = 'parts_of_meetingroom',null = True)

    def disable_from_meeting(self):
        try:
            get_participant = Participant.objects.filter(meeting_id =self.id)
            for get_pp in get_participant:
                get_pp.status = 0
                get_pp.save()
        except:
            LOG_INFO('Organization %s has no PARTICIPANT IN %Ssuser ', self.id)
            pass  
    class Meta:
        app_label = 'testsite'

现在在我看来,当我试图将 start_time 存储在字典中时

            get_all_user_of_org = User.objects.filter(org_name =get_org)

            for user_id in get_all_user_of_org:
                mee_data = {} 
                get_meetings = Meeting.objects.filter(created_by = user_id.id)
                print dir(get_meetings)
                mee_data['start_time'] = get_meetings.start_time 
              #  mee_data['end_time'] = get_meetings
                getall.append(mee_data) 

那我为什么要得到

 AttributeError: 'QuerySet' object has no attribute 'start_time'

这里没有理由显示此错误,因为 start_time 是我的会议表的属性

请帮帮我我会做错什么?

4

2 回答 2

1

Meeting.objects.filter不返回一个Meeting- 它正在返回一个QuerySet会议。您可以遍历QuerySet以获取每个会议的会议时间:

for user_id in get_all_user_of_org:
    mee_data = {} 
    get_meetings = Meeting.objects.filter(created_by = user_id.id)
    print dir(get_meetings)
    for meeting in get_meetings:
        do_something_with(meeting.start_time)

您必须意识到您在这里处理的会议不止一次,而且他们可能有不同的开始时间。在这种情况下,您将最清楚自己想要做什么。大概是这样的吧?

for user_id in get_all_user_of_org:
    get_meetings = Meeting.objects.filter(created_by = user_id.id)
    for meeting in get_meetings:
        mee_data = {} 
        mee_data['start_time'] = meeting.start_time
        getall.append(mee_data)
于 2012-09-13T14:03:16.680 回答
0

那么你正在使用

get_meetings = Meeting.objects.filter(created_by = user_id.id)

这个返回类型filter是一个查询集对象,它可以有一个或多个对象。要获得start_time所有的meetingsa user,你应该使用类似的东西

get_meeting_start_times = Meeting.objects.filter(created_by = user_id.id).values_list('start_time', flat=True)
于 2012-09-13T14:06:08.513 回答