下拉列表外键Django

时间:2019-05-15 05:10:57

标签: python django

美好的一天。我有事要问。

我有一个学生模型,在那个学生模型中,我有外键地址,我要问的是我想从单独的下拉列表中的外键地址创建一个下拉列表,除了zip_code如下图所示:

Student(models.Model):
    ...
    ....
    Address = models.Foreignkey(Address)

Address(models.Model):
    zip_code = models.CharField(...)
    city = model.Charfield(..)
    province= model.Charfield(..)
    country= model.Charfield(..)

谢谢。check here the expected output

1 个答案:

答案 0 :(得分:0)

在views.py中,如下遍历学生对象:

import React, { Component } from 'react';
import styled from 'styled-components';
import H1 from "../common/headings";
import LeftArrow from "../assets/LeftArrow.png";

const MainWrapper = styled.View`
  box-shadow: 5px 5px 5px #000000;

`;

const HeadingWrapper = styled.View`
  padding: 60px 10px 0 10px;
  height: 60px;
  flex: 1;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
`;

const ScrollArea = styled.ScrollView`

`;

const Img = styled.Image`

`;

class LandingPage extends Component {

    render() {
        return (
            <MainWrapper style={styles.mainWrapper}>
                <HeadingWrapper>
                    <Img style={styles.leftArrow} source={LeftArrow}/>
                    <H1>Chats</H1>
                </HeadingWrapper>
                <ScrollArea>

                </ScrollArea>
            </MainWrapper>
        );
    }
}