开发者

Django one form / two models

I have a very simple model for tracking events:

class Event(models.Model):

    description = models.TextField()
    location = models.ForeignKey(Location)    
    start = models.TimeField()
    duration = models.IntegerField()
    event_date =开发者_StackOverflow社区 models.DateField()
    creator = models.ForeignKey(User)

and I opted to extract the location in a separate table in order to be able to perform queries:

class Location(models.Model):

    city = models.CharField(max_length=20)
    address = models.CharField(max_length=30).

What would be the best way to create a form for inserting/updating events, taking into account that the location should be done separately and than linked via ID in the event instance? I wanted to da maybe some autocomplete field for the location address and city, but to keep it on the same form for simplicity?


Define your own widget for the ModelChoiceField in the ModelForm that is generated for the ForeignKey.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜