开发者

How do I make a foreign key appear as its own form instead of a dropdown menu?

I'm trying to create a formset for a list of movies like so:

class MovieList(models.Model):
    user = 开发者_运维知识库models.ForeignKey(User)
    movie = models.ForeignKey(Movie)

class Movie(models.Model):
    genre = models.ForeignKey(Genre)
    name = models.CharField(max_length=300)

MovieListFormSet = inlineformset_factory(User, MovieList)
movielist_formset = MovieListFormSet(instance=currentUser)

Right now "Movie" is appearing as a dropdown menu. However, I'd like it so that "Movie" appears as a blank textbox for 'Movie.name', and a dropdown menu for 'Movie.genre'. The user can enter in the movie name in the textbox and select the genre, and if that movie already exists, MovieList.movie references the existing table row, otherwise a new MovieList row is created and MovieList.movie references the new table row.

How can I do this?


If you want more complex logic, why not to create a new formset from scratch. It shouldn't be much code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜