0

这是我正在尝试做的事情:

用户在我的应用程序中创建了一个事件。这是模型:

class Event(models.Model):
    name = models.CharField(max_length=40)
    organizer = models.ForeignKey(UserProfile)
    description = models.TextField(null=True)
    place = models.TextField(null=True)
    confirmed = models.BigIntegerField(null=True)
    organizer_part = models.BooleanField(default=True)
    slug = models.SlugField()

之后,它会发布受邀参加此活动的不同人员,以及用户选择的不同日期。以下是型号:

class EventDate(models.Model):
    """Correspondances date-event"""
    event = models.ForeignKey(Event)
    date = models.BigIntegerField()


class EventPeople(models.Model):
    """Correspondances personne-event"""
    event = models.ForeignKey(Event)
    phone_number = models.PositiveIntegerField()
    name = models.CharField(max_length=32)
    answer = models.BooleanField()
    participation = models.NullBooleanField()

我只想在一个请求中填写这三个模型。到目前为止,我必须提出三个请求。我看不出我怎么可能做到这一点。

任何想法将不胜感激。

4

1 回答 1

0

应该与您的模型一起使用的资源是:

class EventResource(ModelResource):
    event_dates = fields.ToManyField(EventDateResource, 'event_dates')
    event_peoples = field.ToManyField(EventPeopleResource, 'event_peoples')
    class Meta:
          queryset = Event.objects.all()

您还必须创建简单的 EventDateResource 和 EventPeopleResource。

你的模型再一变化,你需要添加related_names:

class EventDate(models.Model):
    """Correspondances date-event"""
    event = models.ForeignKey(Event, related_name='event_dates')
    date = models.BigIntegerField()


class EventPeople(models.Model):
    """Correspondances personne-event"""
    event = models.ForeignKey(Event, related_name='event_peoples')
    phone_number = models.PositiveIntegerField()
    name = models.CharField(max_length=32)
    answer = models.BooleanField()
    participation = models.NullBooleanField()
于 2013-04-21T00:12:32.270 回答